Re: Unexpected wxSizer::Detach Behavior

jon bird <[email protected]> Sat, 25 Apr 2026 13:26:40 +0100
Newsgroups gmane.comp.lib.wxwindows.general
Organization OnAStickSoftware
Message-ID <[email protected]>
Hi Ryan,

Not sure I have a specific answer to the question you posed however I
do use this to accomplish (I think) something like what you're after.
In my app, there are two columns of 10 buttons in a wxAUI dock - see
image here:

https://www.onasticksoftware.co.uk/about.html

when un-docked, I wanted to re-arrange them into a 4x3 grid (also noting
that allows for an extra 2 buttons):

https://www.oasw.co.uk/public/bwall-move.png

I've accomplished this by detaching the existing sizers and rearranging
everything - here's the code fragment which does this:

https://www.oasw.co.uk/public/bwall-resize.cpp

There's a fair bit to it but the essence is I think based around what
you're talking about.=20

This works nicely under Windows however on Linux, when the window is
re-docked, it crashes somewhere in the gtk layer. Suspect I'm doing
something subtly (or completely) wrong in there somewhere however I've
not found the time to do anything about it.

Rgs,

Jon.

On Sat, 25 Apr 2026 00:12:17 -0400
Kafrene Trading <[email protected]> wrote:

> Hello,
>=20
> I=E2=80=99m a bit confused on the intended usage of wxSizer::Detach. The
> documentation (for the index variant) reads
>=20
> > Detach an item at position index from the sizer without destroying
> > it. =20
>=20
> Which reads as though =E2=80=9Cit=E2=80=9D refers to item, and item refer=
s to the
> wxSizerItem. However, looking at the code for wxSizer::Detach, it is
> clear the item is, in fact, deleted.
>=20
> The window or sizer, if the item =E2=80=9Cheld=E2=80=9D one, is not destr=
oyed, but
> the item itself is, which is surprising to me, since items can be
> more than just windows or sizers.
>=20
> Ultimately this is something of an x-y problem: The actual goal I=E2=80=
=99d
> like to accomplish is being able to remove an item from the sizer,
> and then re-inserting it either immediately or at a later time, maybe
> hiding it for a while in the latter case.
>=20
> It=E2=80=99s not obvious how to accomplish this, afaics. I=E2=80=99d like=
 to preserve
> any item attributes (size, border, align, etc.) and maintain
> abstraction over the underlying kind.
>=20
> I suppose I could check the kind and copy everything manually, but
> that feels less than ideal to have in application code.
>=20
> Is there a better way to do this rather than copying the sizer item
> attributes, detaching, creating a new item with those attributes,
> then inserting? If not, would a PR for something like this (=E2=80=9CDeta=
ch=E2=80=9D,
> though maybe by a different name given the different behavior, which
> accepts a sizer item and does the detach without deleting the item)
> make sense?
>=20
> Thank you,
> Ryan Ogurek
>=20



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

--=20
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---=20
You received this message because you are subscribed to the Google Groups "=
wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/wx-users/20=
260425132640.5305e9e8%40lapdog.onasticksoftware.net.