I would like to set the width of the textboxes of some wxSpinCtrl widgets to an appropriate value such that they can display every valid number without any cutoff and without too much empty space. Given a four digit maximum, I tried to set the width to GetTextExtent(wxString("9999")). However, this sets the total size including UI elements and different UI frameworks have different sizes for these. For example there are two small arrow boxes with gtk2 and windows, but two much larger +/- boxes with gtk3. I suspect that their size also changes depending on display resolution and themes. This means I can't just measure the size of the UI elements and add a fixed amount to the size of the text.
Any suggestions for how to handle this situation?
How to set the size of widgets taking into account the size of UI elements? Topic is solved
-
- In need of some credit
- Posts: 9
- Joined: Mon May 03, 2021 12:20 pm
Re: How to set the size of widgets taking into account the size of UI elements?
wxWindow::GetBestSize() would be the "official" way, that's the value the sizers use for their calculations. But not all controls on all platforms implement it correctly.
Use the source, Luke!
Re: How to set the size of widgets taking into account the size of UI elements?
Hi,
Also keep in mind that some control simply don't have best size (such as wxGrid).
Thank you.
Also keep in mind that some control simply don't have best size (such as wxGrid).
Thank you.
-
- In need of some credit
- Posts: 9
- Joined: Mon May 03, 2021 12:20 pm
Re: How to set the size of widgets taking into account the size of UI elements?
Thanks for the answers. It looks like wxSpinCtrl::GetBestSize() doesn't take min/max values into account with gtk2/3. I guess this is a bug? Is there anything I can do to work around this?
Re: How to set the size of widgets taking into account the size of UI elements?
Why should it? The control just tell you its "personal" preferred best size when no restrictions are set. min/max sizes values are only taken into account by sizers.randomuser wrote: ↑Thu Jul 29, 2021 7:22 pm It looks like wxSpinCtrl::GetBestSize() doesn't take min/max values into account with gtk2/3.
So, is the reported size correct or not?
Use the source, Luke!
-
- In need of some credit
- Posts: 9
- Joined: Mon May 03, 2021 12:20 pm
Re: How to set the size of widgets taking into account the size of UI elements?
It appears I wasn't clear enough. By min/max values, I mean the values that the spin control is allowed to have, not its minimum/maximum size. With gtk2/3, wxSpinCtrl::GetBestSize() always returns the same size independently of these values. So the sizer has the same size if only two-digit numbers are allowed as when seven-digits are allowed, and waste a lot of space as a consequence since the allowed values in my application are much smaller.
Re: How to set the size of widgets taking into account the size of UI elements?
GetBestSize() should use the current value. So if you set the value to "9999" (or whatever) and then call GetBestSize() it should return something reasonable.
Use the source, Luke!
-
- In need of some credit
- Posts: 9
- Joined: Mon May 03, 2021 12:20 pm
Re: How to set the size of widgets taking into account the size of UI elements?
Thank you! This works in 3.1.5 as expected.