wxDialog size not correct - all controls are not shown

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
deepti
Experienced Solver
Experienced Solver
Posts: 88
Joined: Tue Jul 17, 2018 5:38 pm

wxDialog size not correct - all controls are not shown

Post by deepti » Thu Jan 31, 2019 12:10 pm

Hi All,

The following is the structure of my wxDialog instance.


wxPanel
|
wxScrolledWindow
|
wxPanel
|
wxGridSizer
|
Other controls like wxStaticText, wxButton etc.


So, I have a wxPanel p (which has an associated wxBoxSizer s1)
- wxScrolledWindow 'scrwnd' is created with 'p' as parent (scrwnd has an associated wxBoxSizer s2)
It is added like so : s1->Add(scrwnd, 1, wxALL|wxEXPAND, 5);

The above wxPanel and wxScrolledWindow are created statically in the constructor of my dialog.

And then, the below controls are added dynamically, depending on how many of them are needed:
- wxPanel 'pChild' instance is created with wxScrolledWindow instance 'scrwnd' as parent
It is added like so: s2->Add(pChild, 1, wxEXPAND);

- wxGridSizer gs associated with pChild like so : pChild->SetSizer(gs);

And now, several child controls like wxStaticText and wxButton are added to 'gs' like so : gs->Add(childcontrol, 0, wxALL|wxEXPAND, 5);

The problem is that all these child controls are not displayed since the size of the dialog itself is not increasing to dynamically accommodate all the controls.
How should i make the dialog size change depending on the controls that are dynamically added?
Please help!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2933
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDialog size not correct - all controls are not shown

Post by ONEEYEMAN » Thu Jan 31, 2019 3:53 pm

Hi,
Did you call Layout() at the end of the constructor and after adding additional controls?

Thank you.

deepti
Experienced Solver
Experienced Solver
Posts: 88
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxDialog size not correct - all controls are not shown

Post by deepti » Thu Jan 31, 2019 4:43 pm

Hi @Oneyeman,
Thank you for your response.

I have the following lines when controls are added dynamically.

Code: Select all

m_VersionsControlsbox->SetSizeHints(m_VersionsScrolledWindow);
m_VersionsScrolledWindow->FitInside();
m_VersionsControlsbox->FitInside(m_VersionsScrolledWindow);
m_VersionsScrolledWindow->Layout();
m_VersionsControlsbox->Layout();
m_VersionsControlsbox is the sizer associated with the wxScrolledWindow "m_VersionsScrolledWindow".

But there is no call to Layout in the constructor, since only the topmost panel and scrolled window are created there.

Manolo
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 653
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxDialog size not correct - all controls are not shown

Post by Manolo » Thu Jan 31, 2019 4:51 pm

Can you post some minimal code? It's difficult to guess the fix without knowing its origen.

deepti
Experienced Solver
Experienced Solver
Posts: 88
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxDialog size not correct - all controls are not shown

Post by deepti » Thu Jan 31, 2019 5:37 pm

Sure.

Here is the code in the constructor:

Code: Select all

	m_panelVersionSettings = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
	wxBoxSizer* boxSizerVersion = new wxBoxSizer(wxVERTICAL);
	m_panelVersionSettings->SetSizer(boxSizerVersion);

	m_VersionsScrolledWindow = new wxScrolledWindow(m_panelVersionSettings, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxBORDER_SIMPLE | wxVSCROLL);
	m_VersionsScrolledWindow->SetScrollRate(0, 16);

	m_VersionsControlsbox = new wxBoxSizer(wxVERTICAL);

	m_VersionsScrolledWindow->SetSizer(m_VersionsControlsbox);
	boxSizerVersion->Add(m_VersionsScrolledWindow, 1, wxALL | wxEXPAND, 5);
	m_VersionsControlsbox->FitInside(m_VersionsScrolledWindow);
And here is the code which is executed dynamically, depending on some count:

Code: Select all

for (int i = 0; i < metaData.size(); i++)
{
		wxPanel* panelVersionInfo = new wxPanel(m_VersionsScrolledWindow, ++ctrlID, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
				
		m_VersionsControlsbox->Add(panelVersionInfo, 1, wxEXPAND);


		wxGridSizer* fgs = new wxGridSizer(1, 8, 0, 0);
		panelVersionInfo->SetSizer(fgs);

		wxStaticText* versionNum = new wxStaticText(panelVersionInfo, ++ctrlID, versionName, wxDefaultPosition, wxDefaultSize);
		fgs->Add(versionNum, 0, wxALL | wxEXPAND, 5);

		wxStaticText* size = new wxStaticText(panelVersionInfo, ++ctrlID, (*(metaData[i]))["size"], wxDefaultPosition, wxDefaultSize);
		fgs->Add(size, 0, wxALL| wxEXPAND, 5);
		
               //some more controls added.....
}
m_VersionsControlsbox->SetSizeHints(m_VersionsScrolledWindow);
m_VersionsScrolledWindow->FitInside();
m_VersionsControlsbox->FitInside(m_VersionsScrolledWindow);
m_VersionsScrolledWindow->Layout();
m_VersionsControlsbox->Layout();
Last edited by deepti on Thu Jan 31, 2019 5:40 pm, edited 1 time in total.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2933
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDialog size not correct - all controls are not shown

Post by ONEEYEMAN » Thu Jan 31, 2019 5:39 pm

Hi,
This is weird. Why are you calling Layout() 2 times on 2 different object?
What you should do instead is to call Layout() only once for the dialog itself after creating all controls and sizers.

Then when you want to add the control dynamically, you do just that and then call Layout() - again on the dialog itself.

Thank you.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2933
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDialog size not correct - all controls are not shown

Post by ONEEYEMAN » Thu Jan 31, 2019 5:42 pm

Hi,
So you create a panel and scroll window in the constructor and noting else, right? No OK/Cancel buttons, no other controls?

You just need to call Layout() at the end of constructor...

Thank you.

deepti
Experienced Solver
Experienced Solver
Posts: 88
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxDialog size not correct - all controls are not shown

Post by deepti » Thu Jan 31, 2019 5:56 pm

ONEEYEMAN wrote: So you create a panel and scroll window in the constructor and noting else, right? No OK/Cancel buttons, no other controls?
Yes, just that much.

But calling just Layout() for the dialog is not helping :( Its still the same.

Post Reply