How to resize the "Sizer" dynamically (at runtime) Topic is solved

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
User avatar
lionking
Earned a small fee
Earned a small fee
Posts: 17
Joined: Sun Apr 07, 2019 6:07 pm

How to resize the "Sizer" dynamically (at runtime)

Post by lionking »

I have the following structure:

Image

And they are shown in design mode as follow:

Image

By default, these "gauge" and "StaticText" are hidden and at runtime, I show up which one of them.
The problem is when the "StaticText" for example is shown to show a message it doesn't appear correctly at runtime as it was in design mode.

At runtime:
Image

Code: Select all

// The folliwng two lines placed in the constructor of the main window (wxFrame)
this->progressiveSizer->Show(false);
this->messageSizer->Show(false);

// The "messageSizer" will be shown when I click on a boutton
void MainFrm::saveEngineSettings_btn_Click(wxCommandEvent & event) {
    if (getSelectedItemParent(this->engineSettings_tree) != this->engineSettings_tree->GetRootItem()) {
        if(this->Config->Write(this->engineSettings_tree->GetItemText(getSelectedItemParent(this->engineSettings_tree)) + "/" + this->engineSettings_tree->GetItemText(this->engineSettings_tree->GetFocusedItem()), this->engineSettingValue_txt->GetValue())){
            this->Config->Flush(true);
            this->messageSizer->Show(true);
            this->message_label->SetLabel("Data saved successfully");
        }
    }
}


How to make it not overlapping with other elements as it was in design mode?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to resize the "Sizer" dynamically (at runtime)

Post by doublemax »

Try calling infoSizer->Layout() afterwards.

BTW: Unless you intend to add more items to them, progressiveSizer and messageSizer are not needed. Any sizer that contains only one element, doesn't make sense in 99% of cases.
Use the source, Luke!
User avatar
lionking
Earned a small fee
Earned a small fee
Posts: 17
Joined: Sun Apr 07, 2019 6:07 pm

Re: How to resize the "Sizer" dynamically (at runtime)

Post by lionking »

Unfortunately, after applied the "layout()" method the "StaticText" is still overlapped with other elements.

Image

Also, I have changed the structure as follow:

Image

And the following is my code after what has been modified:

Code: Select all

// The following placed in the constructor of the main window (wxFrame)
this->infoSizer->Show(false);
// -----------------------------------------
// The "infoSizer" will be shown when I click on a boutton
void MainFrm::saveEngineSettings_btn_Click(wxCommandEvent & event) {
    if (getSelectedItemParent(this->engineSettings_tree) != this->engineSettings_tree->GetRootItem()) {
        if(this->Config->Write(this->engineSettings_tree->GetItemText(getSelectedItemParent(this->engineSettings_tree)) + "/" + this->engineSettings_tree->GetItemText(this->engineSettings_tree->GetFocusedItem()), this->engineSettingValue_txt->GetValue())){
            this->Config->Flush(true);
            this->infoSizer->Show(true);
            this->message_label->SetLabel("Data saved successfully");
            this->infoSizer->Layout();
        }
    }
}
How to solve that problem?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to resize the "Sizer" dynamically (at runtime)

Post by doublemax »

Also, I have changed the structure as follow:
Does the sizer contain both the wxStaticText and the wxGauge?

Does the position of the text fix itself when you resize the frame manually?

Alternatively, try calling Layout() on the highest sizer in the hierarchy.
Use the source, Luke!
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: How to resize the "Sizer" dynamically (at runtime)

Post by Kvaz1r »

I'm not quite sure but you can try set new size after label changes via:

Code: Select all

this->SetSize(this->GetBestSize());
for your window.
User avatar
lionking
Earned a small fee
Earned a small fee
Posts: 17
Joined: Sun Apr 07, 2019 6:07 pm

Re: How to resize the "Sizer" dynamically (at runtime)

Post by lionking »

Alternatively, try calling Layout() on the highest sizer in the hierarchy.
Now it works well as intended after using "layout()" method on the highest sizer (Main sizer that contains all elements in the wxFrame).
Thank you for helping me. =D>
Post Reply