wxComboBox size behaviour

90 views
Skip to first unread message

jon bird

unread,
Jan 4, 2021, 6:33:11 AM1/4/21
to wx-u...@googlegroups.com
Hi all,

Hopefully a quick one this. I have a series of wxComboBoxes, wrapped in
sizers that allow them to expand as the top level window is resized.
With no strings loaded in them, the behaviour is exactly what I'm
after, they all expand a sensible amount to fill the available space.

However once the boxes have been populated because some of the
strings are quite long, when the window is resized, the width of the
combo boxes are now excessively. Presumably because it's now trying to
allow it to fit the width of the longest string in the box.

It feels like I need to override something like DoGetBestSize or
similar to somehow tell it to disregard the lengths of the strings in
the combo box however it's not clear to me from the docs how to go
about this.

Rgs,


Jon.

--
--
== jon bird - software engineer
== <reply to address _may_ be invalid, real mail below>
== <reduce rsi, stop using the shift key>
== posted as: news 'at' onasticksoftware 'dot' co 'dot' uk

Ian McInerney

unread,
Jan 4, 2021, 7:05:38 AM1/4/21
to wx-u...@googlegroups.com
On Mon, Jan 4, 2021 at 11:33 AM jon bird <ne...@onasticksoftware.co.uk> wrote:
Hi all,

Hopefully a quick one this. I have a series of wxComboBoxes, wrapped in
sizers that allow them to expand as the top level window is resized.
With no strings loaded in them, the behaviour is exactly what I'm
after, they all expand a sensible amount to fill the available space.

However once the boxes have been populated because some of the
strings are quite long, when the window is resized, the width of the
combo boxes are now excessively. Presumably because it's now trying to
allow it to fit the width of the longest string in the box.

It feels like I need to override something like DoGetBestSize or
similar to somehow tell it to disregard the lengths of the strings in
the combo box however it's not clear to me from the docs how to go
about this.

Rgs,


Jon.


Which platform are you seeing this behavior on? I think most platforms use the native comboboxes, so their size is probably computed by the platforms UI system.

--
Ian McInerney
mcia...@gmail.com

No electrons were harmed in the making of this message

jon bird

unread,
Jan 4, 2021, 9:13:09 AM1/4/21
to wx-u...@googlegroups.com
It's on MSW however I've seen similar behaviour on gtk. Ideally I'm trying to avoid all these controls ending up with different sizes as things look a right mess then.

PB

unread,
Jan 4, 2021, 10:31:57 AM1/4/21
to wx-users
Hi,

sorry for a stupid question but did you try calling SetMax(Client)Size()with a desired maximal size? A sizer should respect that, should it not?

Regards,
PB

jon bird

unread,
Jan 4, 2021, 12:03:50 PM1/4/21
to wx-u...@googlegroups.com
Oddly enough calling SetMinSize with a width of roughly the default size I'm after seems to do the trick. Although why that should constrain a max size isn't overly clear to me.

Thanks for the assistance anyway.

Rgs

Jon
Reply all
Reply to author
Forward
0 new messages