Class derived from wxPanel does not show wxListView upon maximizing window

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
liz
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jun 26, 2018 9:26 pm

Class derived from wxPanel does not show wxListView upon maximizing window

Post by liz »

I have a custom class "DataListDisplay" derived from wxPanel. In it there is a wxListView "SettingsList" that is updated after certain user actions. When I am running my application on my monitor that is 1920 x 1200, I have no issues. However, when I run my application on my monitor that is 2560 x 1440 (widescreen), there are display issues with the SettingsList. Specifically, when I maximize the application, the SettingsList disappears. When I restore the window, it does not reappear. If I manually resize the window, then it reappears.

If I set a background color to the DataListDisplay, when the SettingsList disappears, the background color is visible, meaning the wxPanel is displaying properly. If I remove the SettingsList and instead add a simple wxTextCtrl, I have the same issues, so it's not an issue specific to the wxListView. It is something to do with how the wxListView is being added to the wxPanel. I have tried catching EVT_SIZE and calling Layout() and Refresh(), but neither worked. Some example code:

Code: Select all


wxSizer* MainView::CreateSettingsList(wxWindow* parent)
{
	m_pDataList = new DataListDisplay(parent);
	wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
	sizer->AddSpacer(4);
	sizer->Add(m_pDataList);
	return sizer;
}

DataListDisplay::DataListDisplay(wxWindow* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition)
{
	SettingsList = new wxListView(this, wxID_ANY, wxDefaultPosition, wxSize(325, 250), wxLC_REPORT | wxLC_HRULES | wxLC_VRULES);
	
	// various headers and data added ...
	
	wxSizer* sizer = new wxBoxSizer(wxVertical);
	sizer->add(SettingsList, 0, wxExpand);
	SetSizer(sizer);
}

catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Class derived from wxPanel does not show wxListView upon maximizing window

Post by catalin »

You're just not saying anything relevant with that piece of code. You need to show more.
And actually no, seeing the background colour does not mean that anything is right, it could tell you that you are overlapping some widgets or having the wrong parent somewhere (for other windows?).
liz
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jun 26, 2018 9:26 pm

Re: Class derived from wxPanel does not show wxListView upon maximizing window

Post by liz »

What other code would be helpful? I'm not sure what else is relevant.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Class derived from wxPanel does not show wxListView upon maximizing window

Post by catalin »

Where is CreateSettingsList() called from, who is 'parent' that is passed to it, what happens with the returned sizer?
liz
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jun 26, 2018 9:26 pm

Re: Class derived from wxPanel does not show wxListView upon maximizing window

Post by liz »

In MainView, the constructor calls a function CreatePrimaryView(), which calls a function CreateDataAndListRow(), which calls a function CreateSettingsList(). Each of these functions creates a sizer and returns it, until ultimately the MainView constructor takes the sizer from CreatePrimaryView() and adds it to a MainSizer, and then calls SetSizer(MainSizer). It is done this way because there are many other sizers that are added to the MainView, and each of the functions mentioned above also add additional items to those sizers.

MainView constructor calls CreatePrimaryView(this), which is in turn passed down to each function. That is the window eventually passed into the derived wxPanel constructor.

Hopefully that answers your questions! I would post more code, but there are so many unrelated pieces, I think it would just confuse things.
liz
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jun 26, 2018 9:26 pm

Re: Class derived from wxPanel does not show wxListView upon maximizing window

Post by liz »

Also I would like to reiterate that the issue is only with my widescreen monitor. On my non-widescreen monitor, everything shows up fine.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Class derived from wxPanel does not show wxListView upon maximizing window

Post by catalin »

liz wrote:In MainView, the constructor calls a function CreatePrimaryView(), which calls a function CreateDataAndListRow(), which calls a function CreateSettingsList(). Each of these functions creates a sizer and returns it, until ultimately the MainView constructor takes the sizer from CreatePrimaryView() and adds it to a MainSizer, and then calls SetSizer(MainSizer). It is done this way because there are many other sizers that are added to the MainView, and each of the functions mentioned above also add additional items to those sizers.

MainView constructor calls CreatePrimaryView(this), which is in turn passed down to each function. That is the window eventually passed into the derived wxPanel constructor.

Hopefully that answers your questions!
No, it really doesn't. For one thing it is far easier to read a few lines of code [that include comments], than your description. Second, if you have any errors in your code, can you include them in a description?
liz wrote:I would post more code, but there are so many unrelated pieces, I think it would just confuse things.
That is completely true. And that is why you should create the smallest possible piece of code that does not contain unrelated pieces, that you tested and it exhibits the problem, and post that.
liz
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jun 26, 2018 9:26 pm

Re: Class derived from wxPanel does not show wxListView upon maximizing window

Post by liz »

Code: Select all


// MainView is derived from View, which in turn is derived from wxScrolledWindow
MainView::MainView() : View("View Name")
{
	wxSizer* primarySizer = CreatePrimaryView(this);
	
	// Some other sizers are added to topSizer
	wxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL);
	topSizer->Add(primarySizer, 0, wxEXPAND);
	
	// Some other sizers are added to MainSizer
	wxBoxSizer* MainSizer = new wxBoxSizer(wxVERTICAL);
	MainSizer->Add(topSizer, 0, wxCENTRE);
	
	SetSizer(MainSizer);
}

wxSizer* MainView::CreatePrimaryView(wxWindow* parent)
{
	wxSizer* dataAndListRow = CreateDataAndListRow(parent);
	
	// Some other sizers are added as well
	wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
	sizer->Add(dataAndListRow);
	
	return sizer;
}

wxSizer* MainView::CreateDataAndListRow(wxWindow* parent)
{
	wxSizer* list = CreateSettingsList(parent);
	
	// Some other sizers are added as well
	wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
	sizer->Add(list);
	
	return sizer;
}

wxSizer* MainView::CreateSettingsList(wxWindow* parent)
{
	m_pDataList = new DataListDisplay(parent);
	wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
	sizer->AddSpacer(4);
	sizer->Add(m_pDataList);
	return sizer;
}


// The derived wxPanel
DataListDisplay::DataListDisplay(wxWindow* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition)
{
   SettingsList = new wxListView(this, wxID_ANY, wxDefaultPosition, wxSize(325, 250), wxLC_REPORT | wxLC_HRULES | wxLC_VRULES);
   
   // various headers and data added ...
   
   wxSizer* sizer = new wxBoxSizer(wxVertical);
   sizer->add(SettingsList, 0, wxExpand);
   SetSizer(sizer);
}



catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Class derived from wxPanel does not show wxListView upon maximizing window

Post by catalin »

That is definitely not the smallest piece of code that you should have tried with.
What happens with only

Code: Select all

MainView::MainView() : View("View Name")
{
    wxListView* SettingsList = new wxListView(this, wxID_ANY, wxDefaultPosition, wxSize(325, 250), wxLC_REPORT | wxLC_HRULES | wxLC_VRULES);

    wxBoxSizer* MainSizer = new wxBoxSizer(wxVERTICAL);
    MainSizer->Add(SettingsList, 0, wxCENTRE);

    SetSizer(MainSizer);
}
?

Please also read www.catb.org/esr/faqs/smart-questions.html#code, second paragraph.
Post Reply