wxSizer - Sizing items properly. 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
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

wxSizer - Sizing items properly.

Post by apoorv569 »

I have 2 wxBoxSizers in which some items don't get their proportion or sizing correctly. How do I size these items properly?
Here is one of the items, when the app opens with the default size of the frame that I have specified, it looks fine, but as I expand the window, the control widens, this is when the app opens with default wxFrame size,
Image

And on my ultra-wide monitor if I expand the window, the items looks like this,
Image

This slider doesn't need to be that long, is there a way to fix this. Setting the proportion to 0 just draws the circle part of the slider, and nothing else, so it is useless at that point.
Here is the relevant code for this control, all the controls are drawn on the same panel and sizer. the waveform image above has its own sizer but is drawn on the same panel,

Code: Select all

    m_BrowserControlSizer->Add(m_PlayButton, 0, wxALL | wxALIGN_LEFT, 2);
    m_BrowserControlSizer->Add(m_LoopButton, 0, wxALL | wxALIGN_LEFT, 2);
    m_BrowserControlSizer->Add(m_StopButton, 0, wxALL | wxALIGN_LEFT, 2);
    m_BrowserControlSizer->Add(m_SettingsButton, 0, wxALL | wxALIGN_LEFT, 2);
    m_BrowserControlSizer->Add(0,0,5, wxALL | wxEXPAND, 0);
    m_BrowserControlSizer->Add(m_SamplePosition, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 2);
    m_BrowserControlSizer->Add(20,0,0, wxALL | wxEXPAND, 0);
    m_BrowserControlSizer->Add(m_MuteButton, 0, wxALL | wxALIGN_RIGHT, 2);
    m_BrowserControlSizer->Add(m_VolumeSlider, 1, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 2);
    m_BrowserControlSizer->Add(m_AutoPlayCheck, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 2);
And here is another control that I cannot size properly, on default wxFrame size it looks like this,
Image

But if I expand the window, it looks like this,
Image

Setting the proportion to 0 makes it really tiny.
Image

Here is the relevant code for the control, all controls are on the same panel and sizer.

Code: Select all

    m_BottomRightPanelMainSizer->Add(m_SearchBox, 1, wxALL | wxEXPAND, 2);
    m_BottomRightPanelMainSizer->Add(m_InfoBar, 0, wxALL | wxEXPAND, 2);
    m_BottomRightPanelMainSizer->Add(m_SampleListView, 9, wxALL | wxEXPAND, 2);
I want it to be a fixed size and don't expand when the frame size is increased, and also not be so tiny.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxSizer - Sizing items properly.

Post by doublemax »

Use SetMinSize() / SetMaxSize() to restrict the size of these items.

You can restrict the size in only one direction by using something like m_control->SetMinSize( wxSize(250,-1) )
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxSizer - Sizing items properly.

Post by apoorv569 »

doublemax wrote: Sun Jul 04, 2021 11:26 am Use SetMinSize() / SetMaxSize() to restrict the size of these items.

You can restrict the size in only one direction by using something like m_control->SetMinSize( wxSize(250,-1) )
Yes, this works,

Code: Select all

    m_VolumeSlider->SetMinSize(wxSize(140, -1));
    m_VolumeSlider->SetMaxSize(wxSize(140, -1));

    m_SearchBox->SetMinSize(wxSize(-1, 38));
    m_SearchBox->SetMaxSize(wxSize(-1, 38));
Now it looks much better. I matched the search box height with notebook header tab on the left.
Image
Post Reply