Opened 9 years ago

Closed 8 years ago

#11426 closed defect (fixed)

wxSizer does not take out border from hiden child.

Reported by: gszczesz Owned by:
Priority: low Milestone: 2.9.2
Component: GUI-all Version: 2.8.10
Keywords: wxSizer border wxBoxSizer Cc: juliansmart
Blocked By: Blocking:
Patch: no


If a sizer that contains children is hidden (using wxSizer->Show() command from a parent sizer), it's children disappear, but the border around it does not.

This happens only if the wxSizer contains, amongst other children, an empty sizer inside it.

If the child sizer contains wxWindows inside it, everything works fine. The the sizer does not contain a child sizer, everything works fine.

Attached is a minimal example that contains the following: A Frame with a top wxBoxSizer that contains:

(1)-> Text
         (2)-> wxBoxSizer with text and an empty wxBoxSizer (25 border)
         (3)-> wxBoxSizer with text and an empty wxBoxSizer (25 border)
         (4)-> Text

Whenever the space-bar is pressed, #2 and #3 are toggled between hidden and shown. The two texts should be very close to each other when #2 and #3 are hidden, but instead, they are far apart.

If the empty wxBoxSizer is removed from #2 and #3, the two texts will come close. If the empty wxBoxSizer is given a wxWindow to manage, the two texts come close.


Attachments (1)

wxBox issue.cpp download (2.6 KB) - added by gszczesz 9 years ago.
minimal example that illustrates the problem.

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by gszczesz

minimal example that illustrates the problem.

comment:1 Changed 9 years ago by gszczesz

  • Component changed from GUI-all to wxMSW

comment:2 Changed 9 years ago by vadz

  • Cc juliansmart added
  • Component changed from wxMSW to GUI-all
  • Milestone set to 2.9.2
  • Status changed from new to confirmed

This is due to Julian's hack in wxSizerItem::IsShown() which returns true for empty sizers even if they're hidden. It still doesn't make much sense to me (just as when this was introduced) and we can see that it results in really weird problems such as the above.

Julian, would it be a problem for you to use wxRESERVE_SPACE_EVEN_IF_HIDDEN flag and remove this hack? Doing this does fix the problem with this example
(note to self: patch doing this is available in a local git branch)

comment:3 Changed 8 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [65079]) Don't show empty sizers.

Revert the change of r44514 and do hide the empty sizers. Code relying on them
being shown/positioned should use wxRESERVE_SPACE_EVEN_IF_HIDDEN flag but
assuming it by default results in completely unexpected layouts, e.g. still
using margins around a sizer with hidden window if it contains an empty

Closes #11426.

Note: See TracTickets for help on using tickets.