I am on Windows 8.1, with wxWidgets v3.0.3. I am using Visual Studio 2017 Community, and I use the Debug x86 compile option.
I am using 3 wxScrolled<wxWindow> controls (with one of them thus far subclassed) on my wxFrame, and they are arranged with wxButton and wxToggleButton controls on my wxFrame; I use multiple wxBoxSizer sizers to arrange them. But I'm having problems with the display. I have wxALWAYS_SHOW_SB set for all wxScrolled<wxWindow> controls, but scrollbars randomly disappear and reappear when I move my mouse over them. The wxButton and wxToggleButton controls also randomly disappear and reappear when I move my mouse over them. For the subclassed wxScrolled<wxWindow> control, I have overridden OnDraw(), and when I draw an image for it, it appears correctly for a few seconds before disappearing.
What is going on? Is there a problem with using wxScrolled<wxWindow>? Should I use another control instead? I'm trying to create a tile map editor, so I need something that can display tiles and allows for scrolling of them. Am I using too many sizers?
NOTE: I have attached the project. When you run it, find the button on the lower left quadrant of the screen that is captioned with the number "2" and click it, select landscape24.pal. This loads a palette.
Display problems with wxBoxSizer and wxScrolled with wxWindow Topic is solved
Display problems with wxBoxSizer and wxScrolled with wxWindow
- Attachments
-
- sfcTileMapEditor.zip
- (8.84 KiB) Downloaded 78 times
Last edited by beneficii on Mon Jan 29, 2018 8:23 am, edited 1 time in total.
- xaviou
- Super wx Problem Solver
- Posts: 437
- Joined: Mon Aug 21, 2006 3:18 pm
- Location: Annecy - France
- Contact:
Re: Display problems with wxBoxSizer and wxScrolled with wxWindow
Hi.
You should post the code you use to create your interface, because without this, we can't really find where the problem is.
Regards
Xav'
You should post the code you use to create your interface, because without this, we can't really find where the problem is.
Regards
Xav'
My wxWidgets stuff web page : X@v's wxStuff
Re: Display problems with wxBoxSizer and wxScrolled with wxWindow
Just did. See the OP.
- xaviou
- Super wx Problem Solver
- Posts: 437
- Joined: Mon Aug 21, 2006 3:18 pm
- Location: Annecy - France
- Contact:
Re: Display problems with wxBoxSizer and wxScrolled with wxWindow
The main problem with your code is that all your controls are direct children of the frame.
But some of them sould be children of others.
For example, you create a wxPanel (named panel1) and you afect a sizer to it (sizer2)
But the controls managed by this sizer are children of the frame whereas they should be children of the panel itself.
As is, your code is very hard to understand because controls and sizers are not created in their hierarchy order.
You should reorder this to be more comprehensible.
What I usually do is indenting the code for each degree of hierarchy, so I can review it more quickly.
For example, with your code :
With this method, you can more quickly find that sclTiles and btnOpenTiles sould be children of panel1 instead of the frame (so you can replace the 'this' value given for parent with 'panel1'.
And you will also see that you've got a sizer with doesn't manage anything, nor is it associated with any control (sizer6)
You also have 2 controls (stattext and cmbBitSize) witch are not managed by any sizer.
Regards
Xav'
But some of them sould be children of others.
For example, you create a wxPanel (named panel1) and you afect a sizer to it (sizer2)
But the controls managed by this sizer are children of the frame whereas they should be children of the panel itself.
As is, your code is very hard to understand because controls and sizers are not created in their hierarchy order.
You should reorder this to be more comprehensible.
What I usually do is indenting the code for each degree of hierarchy, so I can review it more quickly.
For example, with your code :
Code: Select all
wxBoxSizer *sizer1 = new wxBoxSizer(wxHORIZONTAL);
wxPanel *panel1 = new wxPanel(this, -1, wxDefaultPosition, wxSize(150, 140));
panel1->SetBackgroundColour(*wxGREEN);
wxBoxSizer *sizer2 = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *sizer3 = new wxBoxSizer(wxHORIZONTAL);
sclTiles = new wxScrolled<wxWindow>(this, ID_SCLTILES, wxDefaultPosition, wxSize(150, 80), wxALWAYS_SHOW_SB);
sclTiles->SetBackgroundColour(*wxBLUE);
sizer3->Add(sclTiles, 1, wxEXPAND | wxALL);
btnOpenTiles = new wxButton(this, ID_BTNOPENTILES, "O", wxDefaultPosition, wxSize(30, 30))
sizer3->Add(btnOpenTiles, 0);
sizer2->Add(sizer3, 7, wxEXPAND | wxALL, 10);
panel1->SetSizerAndFit(sizer2);
sizer1->Add(panel1, 1, wxEXPAND | wxALL, 10);
btnSelection = new wxToggleButton(this, -1, "S", wxDefaultPosition, wxSize(30, 30));
sizer1->Add(btnSelection, 0, wxCENTER, 10);
sclTileMap = new wxScrolled<wxWindow>(this, ID_SCLTILEMAP, wxDefaultPosition, wxSize(150, 140), wxALWAYS_SHOW_SB);
sclTileMap->SetBackgroundColour(*wxRED);
sizer1->Add(sclTileMap, 1, wxEXPAND | wxALL, 10);
SetSizerAndFit(sizer1);
And you will also see that you've got a sizer with doesn't manage anything, nor is it associated with any control (sizer6)
You also have 2 controls (stattext and cmbBitSize) witch are not managed by any sizer.
Regards
Xav'
My wxWidgets stuff web page : X@v's wxStuff
Re: Display problems with wxBoxSizer and wxScrolled with wxWindow
Thanks. Making those controls children of panel1 did the trick.
However, with your example of indentation, you deleted a bunch of the controls. So I tried doing the indentation myself, and it's not easy to do. But the window constructs like it should, so thank you!
However, with your example of indentation, you deleted a bunch of the controls. So I tried doing the indentation myself, and it's not easy to do. But the window constructs like it should, so thank you!
- xaviou
- Super wx Problem Solver
- Posts: 437
- Joined: Mon Aug 21, 2006 3:18 pm
- Location: Annecy - France
- Contact:
Re: Display problems with wxBoxSizer and wxScrolled with wxWindow
This was just a portion of code to show you how I generaly do.beneficii wrote:Thanks. Making those controls children of panel1 did the trick.
However, with your example of indentation, you deleted a bunch of the controls. So I tried doing the indentation myself, and it's not easy to do. But the window constructs like it should, so thank you!
Here is your whole code indented (without any correction for the controls parents) :
Code: Select all
wxBoxSizer *sizer1 = new wxBoxSizer(wxHORIZONTAL);
wxPanel *panel1 = new wxPanel(this, -1, wxDefaultPosition, wxSize(150, 140));
panel1->SetBackgroundColour(*wxGREEN);
wxBoxSizer *sizer2 = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *sizer3 = new wxBoxSizer(wxHORIZONTAL);
sclTiles = new wxScrolled<wxWindow>(this, ID_SCLTILES, wxDefaultPosition, wxSize(150, 80), wxALWAYS_SHOW_SB);
sclTiles->SetBackgroundColour(*wxBLUE);
sizer3->Add(sclTiles, 1, wxEXPAND | wxALL);
btnOpenTiles = new wxButton(this, ID_BTNOPENTILES, "O", wxDefaultPosition, wxSize(30, 30));
sizer3->Add(btnOpenTiles, 0);
sizer2->Add(sizer3, 7, wxEXPAND | wxALL, 10);
wxBoxSizer *sizer4 = new wxBoxSizer(wxHORIZONTAL);
sclPalette = new PaletteWindow(this, ID_SCLPALETTE, wxDefaultPosition, wxSize(150, 60), wxALWAYS_SHOW_SB);
sclPalette->SetBackgroundColour(*wxLIGHT_GREY);
sizer4->Add(sclPalette, 1, wxEXPAND | wxALL);
wxBoxSizer *sizer5 = new wxBoxSizer(wxVERTICAL);
btnOpenPalette = new wxButton(this, ID_BTNOPENPALETTE, "O", wxDefaultPosition, wxSize(30, 30));
sizer5->Add(btnOpenPalette, 0);
btnOpenPalette24 = new wxButton(this, ID_BTNOPENPALETTE24, "2", wxDefaultPosition, wxSize(30, 30));
sizer5->Add(btnOpenPalette24, 0);
sizer4->Add(sizer5, 0);
sizer2->Add(sizer4, 5, wxEXPAND | wxALL, 10);
panel1->SetSizerAndFit(sizer2);
sizer1->Add(panel1, 1, wxEXPAND | wxALL, 10);
btnSelection = new wxToggleButton(this, -1, "S", wxDefaultPosition, wxSize(30, 30));
sizer1->Add(btnSelection, 0, wxCENTER, 10);
sclTileMap = new wxScrolled<wxWindow>(this, ID_SCLTILEMAP, wxDefaultPosition, wxSize(150, 140), wxALWAYS_SHOW_SB);
sclTileMap->SetBackgroundColour(*wxBLUE);
sizer1->Add(sclTileMap, 1, wxEXPAND | wxALL, 10);
SetSizerAndFit(sizer1);
wxBoxSizer *sizer6 = new wxBoxSizer(wxHORIZONTAL);
wxStaticText *stattext = new wxStaticText(this, -1, "Graphics: ");
wxArrayString string;
string.Add("2bpp (2 colors)");
string.Add("3bpp (8 colors, left half)");
string.Add("3bpp (8 colors, right half)");
string.Add("4bpp (16 colors)");
string.Add("8bpp (256 colors)");
string.Add("mode 7 (256 colors)");
string.Add("16bpp (direct color)");
cmbBitSize = new wxComboBox(this, ID_CMBBITSIZE, "", wxDefaultPosition, wxDefaultSize, string, wxCB_READONLY);
Xav'
My wxWidgets stuff web page : X@v's wxStuff