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!
wxDialog size not correct - all controls are not shown
Re: wxDialog size not correct - all controls are not shown
Hi,
Did you call Layout() at the end of the constructor and after adding additional controls?
Thank you.
Did you call Layout() at the end of the constructor and after adding additional controls?
Thank you.
Re: wxDialog size not correct - all controls are not shown
Hi @Oneyeman,
Thank you for your response.
I have the following lines when controls are added dynamically.
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.
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();
But there is no call to Layout in the constructor, since only the topmost panel and scrolled window are created there.
Re: wxDialog size not correct - all controls are not shown
Can you post some minimal code? It's difficult to guess the fix without knowing its origen.
Re: wxDialog size not correct - all controls are not shown
Sure.
Here is the code in the constructor:
And here is the code which is executed dynamically, depending on some count:
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);
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.
Re: wxDialog size not correct - all controls are not shown
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.
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.
Re: wxDialog size not correct - all controls are not shown
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.
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.
Re: wxDialog size not correct - all controls are not shown
Yes, just that much.ONEEYEMAN wrote: So you create a panel and scroll window in the constructor and noting else, right? No OK/Cancel buttons, no other controls?
But calling just Layout() for the dialog is not helping Its still the same.