On Sat, 25 Apr 2026 00:12:17 -0400 Kafrene Trading wrote:
KT> I’m a bit confused on the intended usage of wxSizer::Detach. The documentation (for the index variant) reads
KT>
KT> > Detach an item at position index from the sizer without destroying it.
KT>
KT> Which reads as though “it” refers to item, and item refers to the wxSizerItem. However, looking at the code for wxSizer::Detach, it is clear the item is, in fact, deleted.
Yes, this wording is indeed confusing/wrong. It should be changed to "without destroying the sizer or window contained in it" or something like this, I think.
KT> The window or sizer, if the item “held” one, is not destroyed, but the item itself is, which is surprising to me, since items can be more than just windows or sizers.
I also agree that it would make sense to have some wxSizer::DetachItem() that would return the detached item instead of deleting it, so that it could be passed to Add(wxSizerItem*) overload later.
KT> Ultimately this is something of an x-y problem: The actual goal I’d 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.
KT>
KT> It’s not obvious how to accomplish this, afaics. I’d like to preserve any item attributes (size, border, align, etc.) and maintain abstraction over the underlying kind.
KT>
KT> I suppose I could check the kind and copy everything manually, but that feels less than ideal to have in application code.
Yes, indeed.
KT> 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?
I don't think so, unfortunately.
KT> If not, would a PR for something like this (“Detach”, 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?
Yes, adding DetachItem() (or a function with a different name if you have better proposals for it — but not just Detach() because this would be confusing) would make sense and would provide a good solution to your problem.
Thanks!
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
https://www.tt-solutions.com/