Version: 3.2.5
wxSizer Class Referenceabstract

#include <wx/sizer.h>

+ Inheritance diagram for wxSizer:

Detailed Description

wxSizer is the abstract base class used for laying out subwindows in a window.

You cannot use wxSizer directly; instead, you will have to use one of the sizer classes derived from it. Currently there are wxBoxSizer, wxStaticBoxSizer, wxGridSizer, wxFlexGridSizer, wxWrapSizer and wxGridBagSizer.

The layout algorithm used by sizers in wxWidgets is closely related to layout in other GUI toolkits, such as Java's AWT, the GTK toolkit or the Qt toolkit. It is based upon the idea of the individual subwindows reporting their minimal required size and their ability to get stretched if the size of the parent window has changed.

This will most often mean that the programmer does not set the original size of a dialog in the beginning, rather the dialog will be assigned a sizer and this sizer will be queried about the recommended size. The sizer in turn will query its children, which can be normal windows, empty space or other sizers, so that a hierarchy of sizers can be constructed. Note that wxSizer does not derive from wxWindow and thus does not interfere with tab ordering and requires very little resources compared to a real window on screen.

What makes sizers so well fitted for use in wxWidgets is the fact that every control reports its own minimal size and the algorithm can handle differences in font sizes or different window (dialog item) sizes on different platforms without problems. If e.g. the standard font as well as the overall design of Motif widgets requires more space than on Windows, the initial dialog size will automatically be bigger on Motif than on Windows.

Sizers may also be used to control the layout of custom drawn items on the window. The wxSizer::Add(), wxSizer::Insert(), and wxSizer::Prepend() functions return a pointer to the newly added wxSizerItem. Just add empty space of the desired size and attributes, and then use the wxSizerItem::GetRect() method to determine where the drawing operations should take place.

Please notice that sizers, like child windows, are owned by the library and will be deleted by it which implies that they must be allocated on the heap. However if you create a sizer and do not add it to another sizer or window, the library wouldn't be able to delete such an orphan sizer and in this, and only this, case it should be deleted explicitly.

wxSizer flags

The "flag" argument accepted by wxSizerItem constructors and other functions, e.g. wxSizer::Add(), is an OR-combination of the following flags. Two main behaviours are defined using these flags. One is the border around a window: the border parameter determines the border width whereas the flags given here determine which side(s) of the item that the border will be added. The other flags determine how the sizer item behaves when the space allotted to the sizer changes, and is somewhat dependent on the specific kind of sizer used.

wxTOP
wxBOTTOM
wxLEFT
wxRIGHT
wxALL
These flags are used to specify which side(s) of the sizer item the border width will apply to.
wxEXPAND The item will be expanded to fill the space assigned to the item. When used for the items of wxBoxSizer, the expansion only happens in the transversal direction of the sizer as only the item proportion governs its behaviour in the principal sizer direction. But when it is used for the items of wxGridSizer, this flag can be combined with the alignment flags which override it in the corresponding direction if specified, e.g. wxEXPAND | wxALIGN_CENTRE_VERTICAL would expand the item only horizontally but center it vertically. Notice that this doesn't work for the default left/top alignment and wxEXPAND still applies in both directions if it is combined with wxALIGN_LEFT or wxALIGN_TOP.
wxSHAPED The item will be expanded as much as possible while also maintaining its aspect ratio.
wxFIXED_MINSIZE Normally sizers use the "best", i.e. most appropriate, size of the window to determine what the minimal size of window items should be. This allows layouts to adjust correctly when the item contents, and hence its best size, changes. If this behaviour is unwanted, wxFIXED_MINSIZE can be used to fix minimal size of the window to its initial value and not change it any more in the future. Note that the same thing can be accomplished by calling wxWindow::SetMinSize() explicitly as well.
wxRESERVE_SPACE_EVEN_IF_HIDDEN Normally wxSizers don't allocate space for hidden windows or other items. This flag overrides this behaviour so that sufficient space is allocated for the window even if it isn't visible. This makes it possible to dynamically show and hide controls without resizing parent dialog, for example. (Available since 2.8.8.)
wxALIGN_CENTER
wxALIGN_CENTRE
wxALIGN_LEFT
wxALIGN_RIGHT
wxALIGN_TOP
wxALIGN_BOTTOM
wxALIGN_CENTER_VERTICAL
wxALIGN_CENTRE_VERTICAL
wxALIGN_CENTER_HORIZONTAL
wxALIGN_CENTRE_HORIZONTAL
The wxALIGN_* flags allow you to specify the alignment of the item within the space allotted to it by the sizer, adjusted for the border if any.

Library:  wxCore
Category:  Window Layout
See also
Sizers Overview

Public Member Functions

 wxSizer ()
 The constructor. More...
 
virtual ~wxSizer ()
 The destructor. More...
 
wxSizerItemAdd (wxWindow *window, const wxSizerFlags &flags)
 Appends a child to the sizer. More...
 
wxSizerItemAdd (wxWindow *window, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 Appends a child to the sizer. More...
 
wxSizerItemAdd (wxSizer *sizer, const wxSizerFlags &flags)
 Appends a child to the sizer. More...
 
wxSizerItemAdd (wxSizer *sizer, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 Appends a child to the sizer. More...
 
wxSizerItemAdd (int width, int height, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 Appends a spacer child to the sizer. More...
 
wxSizerItemAdd (int width, int height, const wxSizerFlags &flags)
 Appends a spacer child to the sizer. More...
 
wxSizerItemAdd (wxSizerItem *item)
 
virtual wxSizerItemAddSpacer (int size)
 This base function adds non-stretchable space to both the horizontal and vertical orientation of the sizer. More...
 
wxSizerItemAddStretchSpacer (int prop=1)
 Adds stretchable space to the sizer. More...
 
virtual wxSize CalcMin ()=0
 This method is abstract and has to be overwritten by any derived class. More...
 
virtual void Clear (bool delete_windows=false)
 Detaches all children from the sizer. More...
 
wxSize ComputeFittingClientSize (wxWindow *window)
 Computes client area size for window so that it matches the sizer's minimal size. More...
 
wxSize ComputeFittingWindowSize (wxWindow *window)
 Like ComputeFittingClientSize(), but converts the result into window size. More...
 
virtual bool Detach (wxWindow *window)
 Detach the child window from the sizer without destroying it. More...
 
virtual bool Detach (wxSizer *sizer)
 Detach the child sizer from the sizer without destroying it. More...
 
virtual bool Detach (int index)
 Detach an item at position index from the sizer without destroying it. More...
 
wxSize Fit (wxWindow *window)
 Tell the sizer to resize the window so that its client area matches the sizer's minimal size (ComputeFittingClientSize() is called to determine it). More...
 
void FitInside (wxWindow *window)
 Tell the sizer to resize the virtual size of the window to match the sizer's minimal size. More...
 
virtual bool InformFirstDirection (int direction, int size, int availableOtherDir)
 Inform sizer about the first direction that has been decided (by parent item). More...
 
wxWindowGetContainingWindow () const
 Returns the window this sizer is used in or NULL if none. More...
 
void SetContainingWindow (wxWindow *window)
 Set the window this sizer is used in. More...
 
size_t GetItemCount () const
 Returns the number of items in the sizer. More...
 
wxSizerItemGetItem (wxWindow *window, bool recursive=false)
 Finds the wxSizerItem which holds the given window. More...
 
wxSizerItemGetItem (wxSizer *sizer, bool recursive=false)
 Finds the wxSizerItem which holds the given sizer. More...
 
wxSizerItemGetItem (size_t index)
 Finds the wxSizerItem which is located in the sizer at position index. More...
 
wxSizerItemGetItemById (int id, bool recursive=false)
 Finds the item in the sizer which has the given id. More...
 
wxSize GetMinSize ()
 Returns the minimal size of the sizer. More...
 
wxPoint GetPosition () const
 Returns the current position of the sizer. More...
 
wxSize GetSize () const
 Returns the current size of the sizer. More...
 
bool Hide (wxWindow *window, bool recursive=false)
 Hides the child window. More...
 
bool Hide (wxSizer *sizer, bool recursive=false)
 Hides the child sizer. More...
 
bool Hide (size_t index)
 Hides the item at position index. More...
 
wxSizerItemInsert (size_t index, wxWindow *window, const wxSizerFlags &flags)
 Insert a child into the sizer before any existing item at index. More...
 
wxSizerItemInsert (size_t index, wxWindow *window, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 Insert a child into the sizer before any existing item at index. More...
 
wxSizerItemInsert (size_t index, wxSizer *sizer, const wxSizerFlags &flags)
 Insert a child into the sizer before any existing item at index. More...
 
wxSizerItemInsert (size_t index, wxSizer *sizer, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 Insert a child into the sizer before any existing item at index. More...
 
wxSizerItemInsert (size_t index, int width, int height, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 Insert a child into the sizer before any existing item at index. More...
 
wxSizerItemInsert (size_t index, int width, int height, const wxSizerFlags &flags)
 Insert a child into the sizer before any existing item at index. More...
 
wxSizerItemInsert (size_t index, wxSizerItem *item)
 
wxSizerItemInsertSpacer (size_t index, int size)
 Inserts non-stretchable space to the sizer. More...
 
wxSizerItemInsertStretchSpacer (size_t index, int prop=1)
 Inserts stretchable space to the sizer. More...
 
bool IsEmpty () const
 Return true if the sizer has no elements. More...
 
bool IsShown (wxWindow *window) const
 Returns true if the window is shown. More...
 
bool IsShown (wxSizer *sizer) const
 Returns true if the sizer is shown. More...
 
bool IsShown (size_t index) const
 Returns true if the item at index is shown. More...
 
virtual void Layout ()
 Call this to force layout of the children anew, e.g. after having added a child to or removed a child (window, other sizer or space) from the sizer while keeping the current dimension. More...
 
wxSizerItemPrepend (wxWindow *window, const wxSizerFlags &flags)
 Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer. More...
 
wxSizerItemPrepend (wxWindow *window, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer. More...
 
wxSizerItemPrepend (wxSizer *sizer, const wxSizerFlags &flags)
 Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer. More...
 
wxSizerItemPrepend (wxSizer *sizer, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer. More...
 
wxSizerItemPrepend (int width, int height, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer. More...
 
wxSizerItemPrepend (int width, int height, const wxSizerFlags &flags)
 Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer. More...
 
wxSizerItemPrepend (wxSizerItem *item)
 
wxSizerItemPrependSpacer (int size)
 Prepends non-stretchable space to the sizer. More...
 
wxSizerItemPrependStretchSpacer (int prop=1)
 Prepends stretchable space to the sizer. More...
 
virtual void RepositionChildren (const wxSize &minSize)=0
 Method which must be overridden in the derived sizer classes. More...
 
virtual bool Remove (wxWindow *window)
 Removes a child window from the sizer, but does not destroy it (because windows are owned by their parent window, not the sizer). More...
 
virtual bool Remove (wxSizer *sizer)
 Removes a sizer child from the sizer and destroys it. More...
 
virtual bool Remove (int index)
 Removes a child from the sizer and destroys it if it is a sizer or a spacer, but not if it is a window (because windows are owned by their parent window, not the sizer). More...
 
virtual bool Replace (wxWindow *oldwin, wxWindow *newwin, bool recursive=false)
 Detaches the given oldwin from the sizer and replaces it with the given newwin. More...
 
virtual bool Replace (wxSizer *oldsz, wxSizer *newsz, bool recursive=false)
 Detaches the given oldsz from the sizer and replaces it with the given newsz. More...
 
virtual bool Replace (size_t index, wxSizerItem *newitem)
 Detaches the given item at position index from the sizer and replaces it with the given wxSizerItem newitem. More...
 
void SetDimension (int x, int y, int width, int height)
 Call this to force the sizer to take the given dimension and thus force the items owned by the sizer to resize themselves according to the rules defined by the parameter in the Add() and Prepend() methods. More...
 
void SetDimension (const wxPoint &pos, const wxSize &size)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void SetMinSize (const wxSize &size)
 Call this to give the sizer a minimal size. More...
 
void SetMinSize (int width, int height)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void SetSizeHints (wxWindow *window)
 This method first calls Fit() and then wxTopLevelWindow::SetSizeHints() on the window passed to it. More...
 
void SetVirtualSizeHints (wxWindow *window)
 Tell the sizer to set the minimal size of the window virtual area to match the sizer's minimal size. More...
 
bool Show (wxWindow *window, bool show=true, bool recursive=false)
 Shows or hides the window. More...
 
bool Show (wxSizer *sizer, bool show=true, bool recursive=false)
 Shows or hides sizer. More...
 
bool Show (size_t index, bool show=true)
 Shows the item at index. More...
 
virtual void ShowItems (bool show)
 Show or hide all items managed by the sizer. More...
 
wxSizerItemList & GetChildren ()
 Returns the list of the items in this sizer. More...
 
const wxSizerItemList & GetChildren () const
 Returns the list of the items in this sizer. More...
 
bool SetItemMinSize (wxWindow *window, int width, int height)
 Set an item's minimum size by window, sizer, or position. More...
 
bool SetItemMinSize (wxWindow *window, const wxSize &size)
 Set an item's minimum size by window, sizer, or position. More...
 
bool SetItemMinSize (wxSizer *sizer, int width, int height)
 Set an item's minimum size by window, sizer, or position. More...
 
bool SetItemMinSize (wxSizer *sizer, const wxSize &size)
 Set an item's minimum size by window, sizer, or position. More...
 
bool SetItemMinSize (size_t index, int width, int height)
 Set an item's minimum size by window, sizer, or position. More...
 
bool SetItemMinSize (size_t index, const wxSize &size)
 Set an item's minimum size by window, sizer, or position. More...
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 

Additional Inherited Members

- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

◆ wxSizer()

wxSizer::wxSizer ( )

The constructor.

Note that wxSizer is an abstract base class and may not be instantiated.

◆ ~wxSizer()

virtual wxSizer::~wxSizer ( )
virtual

The destructor.

Member Function Documentation

◆ Add() [1/7]

wxSizerItem* wxSizer::Add ( int  width,
int  height,
const wxSizerFlags flags 
)

Appends a spacer child to the sizer.

Parameters
widthWidth of the spacer.
heightHeight of the spacer.
flagsA wxSizerFlags object that enables you to specify most of the other parameters more conveniently.

◆ Add() [2/7]

wxSizerItem* wxSizer::Add ( int  width,
int  height,
int  proportion = 0,
int  flag = 0,
int  border = 0,
wxObject userData = NULL 
)

Appends a spacer child to the sizer.

wxSizer itself is an abstract class, but the parameters are equivalent in the derived classes that you will instantiate to use it so they are described here.

width and height specify the dimension of a spacer to be added to the sizer. Adding spacers to sizers gives more flexibility in the design of dialogs; imagine for example a horizontal box with two buttons at the bottom of a dialog: you might want to insert a space between the two buttons and make that space stretchable using the proportion flag and the result will be that the left button will be aligned with the left side of the dialog and the right button with the right side - the space in between will shrink and grow with the dialog.

Parameters
widthWidth of the spacer.
heightHeight of the spacer.
proportionAlthough the meaning of this parameter is undefined in wxSizer, it is used in wxBoxSizer to indicate if a child of a sizer can change its size in the main orientation of the wxBoxSizer - where 0 stands for not changeable and a value of more than zero is interpreted relative to the value of other children of the same wxBoxSizer. For example, you might have a horizontal wxBoxSizer with three children, two of which are supposed to change their size with the sizer. Then the two stretchable windows would get a value of 1 each to make them grow and shrink equally with the sizer's horizontal dimension.
flagOR-combination of flags affecting sizer's behaviour. See wxSizer flags list for details.
borderDetermines the border width, if the flag parameter is set to include any border flag.
userDataAllows an extra object to be attached to the sizer item, for use in derived classes when sizing information is more complex than the proportion and flag will allow for.

◆ Add() [3/7]

wxSizerItem* wxSizer::Add ( wxSizer sizer,
const wxSizerFlags flags 
)

Appends a child to the sizer.

wxSizer itself is an abstract class, but the parameters are equivalent in the derived classes that you will instantiate to use it so they are described here:

Parameters
sizerThe (child-)sizer to be added to the sizer. This allows placing a child sizer in a sizer and thus to create hierarchies of sizers (typically a vertical box as the top sizer and several horizontal boxes on the level beneath).
flagsA wxSizerFlags object that enables you to specify most of the above parameters more conveniently.

◆ Add() [4/7]

wxSizerItem* wxSizer::Add ( wxSizer sizer,
int  proportion = 0,
int  flag = 0,
int  border = 0,
wxObject userData = NULL 
)

Appends a child to the sizer.

wxSizer itself is an abstract class, but the parameters are equivalent in the derived classes that you will instantiate to use it so they are described here:

Parameters
sizerThe (child-)sizer to be added to the sizer. This allows placing a child sizer in a sizer and thus to create hierarchies of sizers (typically a vertical box as the top sizer and several horizontal boxes on the level beneath).
proportionAlthough the meaning of this parameter is undefined in wxSizer, it is used in wxBoxSizer to indicate if a child of a sizer can change its size in the main orientation of the wxBoxSizer - where 0 stands for not changeable and a value of more than zero is interpreted relative to the value of other children of the same wxBoxSizer. For example, you might have a horizontal wxBoxSizer with three children, two of which are supposed to change their size with the sizer. Then the two stretchable windows would get a value of 1 each to make them grow and shrink equally with the sizer's horizontal dimension.
flagOR-combination of flags affecting sizer's behaviour. See wxSizer flags list for details.
borderDetermines the border width, if the flag parameter is set to include any border flag.
userDataAllows an extra object to be attached to the sizer item, for use in derived classes when sizing information is more complex than the proportion and flag will allow for.

◆ Add() [5/7]

wxSizerItem* wxSizer::Add ( wxSizerItem item)

◆ Add() [6/7]

wxSizerItem* wxSizer::Add ( wxWindow window,
const wxSizerFlags flags 
)

Appends a child to the sizer.

wxSizer itself is an abstract class, but the parameters are equivalent in the derived classes that you will instantiate to use it so they are described here:

Parameters
windowThe window to be added to the sizer. Its initial size (either set explicitly by the user or calculated internally when using wxDefaultSize) is interpreted as the minimal and in many cases also the initial size.
flagsA wxSizerFlags object that enables you to specify most of the above parameters more conveniently.

◆ Add() [7/7]

wxSizerItem* wxSizer::Add ( wxWindow window,
int  proportion = 0,
int  flag = 0,
int  border = 0,
wxObject userData = NULL 
)

Appends a child to the sizer.

wxSizer itself is an abstract class, but the parameters are equivalent in the derived classes that you will instantiate to use it so they are described here:

Parameters
windowThe window to be added to the sizer. Its initial size (either set explicitly by the user or calculated internally when using wxDefaultSize) is interpreted as the minimal and in many cases also the initial size.
proportionAlthough the meaning of this parameter is undefined in wxSizer, it is used in wxBoxSizer to indicate if a child of a sizer can change its size in the main orientation of the wxBoxSizer - where 0 stands for not changeable and a value of more than zero is interpreted relative to the value of other children of the same wxBoxSizer. For example, you might have a horizontal wxBoxSizer with three children, two of which are supposed to change their size with the sizer. Then the two stretchable windows would get a value of 1 each to make them grow and shrink equally with the sizer's horizontal dimension.
flagOR-combination of flags affecting sizer's behaviour. See wxSizer flags list for details.
borderDetermines the border width, if the flag parameter is set to include any border flag.
userDataAllows an extra object to be attached to the sizer item, for use in derived classes when sizing information is more complex than the proportion and flag will allow for.

◆ AddSpacer()

virtual wxSizerItem* wxSizer::AddSpacer ( int  size)
virtual

This base function adds non-stretchable space to both the horizontal and vertical orientation of the sizer.

More readable way of calling:

wxSizer::Add(size, size, 0).
wxSizerItem * Add(wxWindow *window, const wxSizerFlags &flags)
Appends a child to the sizer.
See also
wxBoxSizer::AddSpacer()

Reimplemented in wxBoxSizer.

◆ AddStretchSpacer()

wxSizerItem* wxSizer::AddStretchSpacer ( int  prop = 1)

Adds stretchable space to the sizer.

More readable way of calling:

wxSizer::Add(0, 0, prop).

◆ CalcMin()

virtual wxSize wxSizer::CalcMin ( )
pure virtual

This method is abstract and has to be overwritten by any derived class.

Here, the sizer will do the actual calculation of its children's minimal sizes.

Implemented in wxWrapSizer, wxBoxSizer, wxStaticBoxSizer, wxGridSizer, wxFlexGridSizer, wxStdDialogButtonSizer, and wxGridBagSizer.

◆ Clear()

virtual void wxSizer::Clear ( bool  delete_windows = false)
virtual

Detaches all children from the sizer.

If delete_windows is true then child windows will also be deleted.

Notice that child sizers are always deleted, as a general consequence of the principle that sizers own their sizer children, but don't own their window children (because they are already owned by their parent windows).

◆ ComputeFittingClientSize()

wxSize wxSizer::ComputeFittingClientSize ( wxWindow window)

Computes client area size for window so that it matches the sizer's minimal size.

Unlike GetMinSize(), this method accounts for other constraints imposed on window, namely display's size (returned size will never be too large for the display) and maximum window size if previously set by wxWindow::SetMaxSize().

The returned value is suitable for passing to wxWindow::SetClientSize() or wxWindow::SetMinClientSize().

Since
2.8.8
See also
ComputeFittingWindowSize(), Fit()

◆ ComputeFittingWindowSize()

wxSize wxSizer::ComputeFittingWindowSize ( wxWindow window)

Like ComputeFittingClientSize(), but converts the result into window size.

The returned value is suitable for passing to wxWindow::SetSize() or wxWindow::SetMinSize().

Since
2.8.8
See also
ComputeFittingClientSize(), Fit()

◆ Detach() [1/3]

virtual bool wxSizer::Detach ( int  index)
virtual

Detach an item at position index from the sizer without destroying it.

This method does not cause any layout or resizing to take place, call Layout() to update the layout "on screen" after detaching a child from the sizer. Returns true if the child item was found and detached, false otherwise.

See also
Remove()

◆ Detach() [2/3]

virtual bool wxSizer::Detach ( wxSizer sizer)
virtual

Detach the child sizer from the sizer without destroying it.

This method does not cause any layout or resizing to take place, call Layout() to update the layout "on screen" after detaching a child from the sizer.

Returns true if the child item was found and detached, false otherwise.

See also
Remove()

◆ Detach() [3/3]

virtual bool wxSizer::Detach ( wxWindow window)
virtual

Detach the child window from the sizer without destroying it.

This method does not cause any layout or resizing to take place, call Layout() to update the layout "on screen" after detaching a child from the sizer.

Returns true if the child item was found and detached, false otherwise.

See also
Remove()

◆ Fit()

wxSize wxSizer::Fit ( wxWindow window)

Tell the sizer to resize the window so that its client area matches the sizer's minimal size (ComputeFittingClientSize() is called to determine it).

This is commonly done in the constructor of the window itself, see sample in the description of wxBoxSizer.

Returns
The new window size.
See also
ComputeFittingClientSize(), ComputeFittingWindowSize()

◆ FitInside()

void wxSizer::FitInside ( wxWindow window)

Tell the sizer to resize the virtual size of the window to match the sizer's minimal size.

This will not alter the on screen size of the window, but may cause the addition/removal/alteration of scrollbars required to view the virtual area in windows which manage it.

See also
wxScrolled::SetScrollbars(), SetVirtualSizeHints()

◆ GetChildren() [1/2]

wxSizerItemList& wxSizer::GetChildren ( )

Returns the list of the items in this sizer.

The elements of type-safe wxList wxSizerItemList are pointers to objects of type wxSizerItem.

◆ GetChildren() [2/2]

const wxSizerItemList& wxSizer::GetChildren ( ) const

Returns the list of the items in this sizer.

The elements of type-safe wxList wxSizerItemList are pointers to objects of type wxSizerItem.

◆ GetContainingWindow()

wxWindow* wxSizer::GetContainingWindow ( ) const

Returns the window this sizer is used in or NULL if none.

◆ GetItem() [1/3]

wxSizerItem* wxSizer::GetItem ( size_t  index)

Finds the wxSizerItem which is located in the sizer at position index.

Returns
Pointer to the item or NULL if there is no item at that index.

◆ GetItem() [2/3]

wxSizerItem* wxSizer::GetItem ( wxSizer sizer,
bool  recursive = false 
)

Finds the wxSizerItem which holds the given sizer.

Use parameter recursive to search in subsizers too.

Returns
Pointer to the item or NULL if the given sizer is not in the sizer.

◆ GetItem() [3/3]

wxSizerItem* wxSizer::GetItem ( wxWindow window,
bool  recursive = false 
)

Finds the wxSizerItem which holds the given window.

Use parameter recursive to search in subsizers too.

Returns
Pointer to the item or NULL if there is no item with the window.

◆ GetItemById()

wxSizerItem* wxSizer::GetItemById ( int  id,
bool  recursive = false 
)

Finds the item in the sizer which has the given id.

This id is not the window id but the id of the wxSizerItem itself. This is mainly useful for retrieving the sizers created from XRC resources. Use parameter recursive to search in subsizers too.

Returns
Pointer to item or NULL if no item has that id.

◆ GetItemCount()

size_t wxSizer::GetItemCount ( ) const

Returns the number of items in the sizer.

If you just need to test whether the sizer is empty or not you can also use the IsEmpty() function.

◆ GetMinSize()

wxSize wxSizer::GetMinSize ( )

Returns the minimal size of the sizer.

This is either the combined minimal size of all the children and their borders or the minimal size set by SetMinSize(), depending on which is bigger. Note that the returned value is client size, not window size. In particular, if you use the value to set toplevel window's minimal or actual size, use wxWindow::SetMinClientSize() or wxWindow::SetClientSize(), not wxWindow::SetMinSize() or wxWindow::SetSize().

◆ GetPosition()

wxPoint wxSizer::GetPosition ( ) const

Returns the current position of the sizer.

◆ GetSize()

wxSize wxSizer::GetSize ( ) const

Returns the current size of the sizer.

◆ Hide() [1/3]

bool wxSizer::Hide ( size_t  index)

Hides the item at position index.

To make a sizer item disappear, use Hide() followed by Layout().

Use parameter recursive to hide elements found in subsizers. Returns true if the child item was found, false otherwise.

See also
IsShown(), Show()

◆ Hide() [2/3]

bool wxSizer::Hide ( wxSizer sizer,
bool  recursive = false 
)

Hides the child sizer.

To make a sizer item disappear, use Hide() followed by Layout().

Use parameter recursive to hide elements found in subsizers. Returns true if the child item was found, false otherwise.

See also
IsShown(), Show()

◆ Hide() [3/3]

bool wxSizer::Hide ( wxWindow window,
bool  recursive = false 
)

Hides the child window.

To make a sizer item disappear, use Hide() followed by Layout().

Use parameter recursive to hide elements found in subsizers. Returns true if the child item was found, false otherwise.

See also
IsShown(), Show()

◆ InformFirstDirection()

virtual bool wxSizer::InformFirstDirection ( int  direction,
int  size,
int  availableOtherDir 
)
virtual

Inform sizer about the first direction that has been decided (by parent item).

Returns true if it made use of the information (and recalculated min size).

Reimplemented in wxWrapSizer.

◆ Insert() [1/7]

wxSizerItem* wxSizer::Insert ( size_t  index,
int  width,
int  height,
const wxSizerFlags flags 
)

Insert a child into the sizer before any existing item at index.

See Add() for the meaning of the other parameters.

◆ Insert() [2/7]

wxSizerItem* wxSizer::Insert ( size_t  index,
int  width,
int  height,
int  proportion = 0,
int  flag = 0,
int  border = 0,
wxObject userData = NULL 
)

Insert a child into the sizer before any existing item at index.

See Add() for the meaning of the other parameters.

◆ Insert() [3/7]

wxSizerItem* wxSizer::Insert ( size_t  index,
wxSizer sizer,
const wxSizerFlags flags 
)

Insert a child into the sizer before any existing item at index.

See Add() for the meaning of the other parameters.

◆ Insert() [4/7]

wxSizerItem* wxSizer::Insert ( size_t  index,
wxSizer sizer,
int  proportion = 0,
int  flag = 0,
int  border = 0,
wxObject userData = NULL 
)

Insert a child into the sizer before any existing item at index.

See Add() for the meaning of the other parameters.

◆ Insert() [5/7]

wxSizerItem* wxSizer::Insert ( size_t  index,
wxSizerItem item 
)

◆ Insert() [6/7]

wxSizerItem* wxSizer::Insert ( size_t  index,
wxWindow window,
const wxSizerFlags flags 
)

Insert a child into the sizer before any existing item at index.

See Add() for the meaning of the other parameters.

◆ Insert() [7/7]

wxSizerItem* wxSizer::Insert ( size_t  index,
wxWindow window,
int  proportion = 0,
int  flag = 0,
int  border = 0,
wxObject userData = NULL 
)

Insert a child into the sizer before any existing item at index.

See Add() for the meaning of the other parameters.

◆ InsertSpacer()

wxSizerItem* wxSizer::InsertSpacer ( size_t  index,
int  size 
)

Inserts non-stretchable space to the sizer.

More readable way of calling wxSizer::Insert(index, size, size).

◆ InsertStretchSpacer()

wxSizerItem* wxSizer::InsertStretchSpacer ( size_t  index,
int  prop = 1 
)

Inserts stretchable space to the sizer.

More readable way of calling wxSizer::Insert(0, 0, prop).

◆ IsEmpty()

bool wxSizer::IsEmpty ( ) const

Return true if the sizer has no elements.

See also
GetItemCount()

◆ IsShown() [1/3]

bool wxSizer::IsShown ( size_t  index) const

Returns true if the item at index is shown.

See also
Hide(), Show(), wxSizerItem::IsShown()

◆ IsShown() [2/3]

bool wxSizer::IsShown ( wxSizer sizer) const

Returns true if the sizer is shown.

See also
Hide(), Show(), wxSizerItem::IsShown()

◆ IsShown() [3/3]

bool wxSizer::IsShown ( wxWindow window) const

Returns true if the window is shown.

See also
Hide(), Show(), wxSizerItem::IsShown()

◆ Layout()

virtual void wxSizer::Layout ( )
virtual

Call this to force layout of the children anew, e.g. after having added a child to or removed a child (window, other sizer or space) from the sizer while keeping the current dimension.

◆ Prepend() [1/7]

wxSizerItem* wxSizer::Prepend ( int  width,
int  height,
const wxSizerFlags flags 
)

Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer.

◆ Prepend() [2/7]

wxSizerItem* wxSizer::Prepend ( int  width,
int  height,
int  proportion = 0,
int  flag = 0,
int  border = 0,
wxObject userData = NULL 
)

Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer.

◆ Prepend() [3/7]

wxSizerItem* wxSizer::Prepend ( wxSizer sizer,
const wxSizerFlags flags 
)

Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer.

◆ Prepend() [4/7]

wxSizerItem* wxSizer::Prepend ( wxSizer sizer,
int  proportion = 0,
int  flag = 0,
int  border = 0,
wxObject userData = NULL 
)

Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer.

◆ Prepend() [5/7]

wxSizerItem* wxSizer::Prepend ( wxSizerItem item)

◆ Prepend() [6/7]

wxSizerItem* wxSizer::Prepend ( wxWindow window,
const wxSizerFlags flags 
)

Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer.

◆ Prepend() [7/7]

wxSizerItem* wxSizer::Prepend ( wxWindow window,
int  proportion = 0,
int  flag = 0,
int  border = 0,
wxObject userData = NULL 
)

Same as Add(), but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer.

◆ PrependSpacer()

wxSizerItem* wxSizer::PrependSpacer ( int  size)

Prepends non-stretchable space to the sizer.

More readable way of calling wxSizer::Prepend(size, size, 0).

◆ PrependStretchSpacer()

wxSizerItem* wxSizer::PrependStretchSpacer ( int  prop = 1)

Prepends stretchable space to the sizer.

More readable way of calling wxSizer::Prepend(0, 0, prop).

◆ Remove() [1/3]

virtual bool wxSizer::Remove ( int  index)
virtual

Removes a child from the sizer and destroys it if it is a sizer or a spacer, but not if it is a window (because windows are owned by their parent window, not the sizer).

Note
This method does not cause any layout or resizing to take place, call Layout() to update the layout "on screen" after removing a child from the sizer.
Parameters
indexThe position of the child in the sizer, e.g. 0 for the first item.
Returns
true if the child item was found and removed, false otherwise.

◆ Remove() [2/3]

virtual bool wxSizer::Remove ( wxSizer sizer)
virtual

Removes a sizer child from the sizer and destroys it.

Note
This method does not cause any layout or resizing to take place, call Layout() to update the layout "on screen" after removing a child from the sizer.
Parameters
sizerThe wxSizer to be removed.
Returns
true if the child item was found and removed, false otherwise.

◆ Remove() [3/3]

virtual bool wxSizer::Remove ( wxWindow window)
virtual

Removes a child window from the sizer, but does not destroy it (because windows are owned by their parent window, not the sizer).

Deprecated:
The overload of this method taking a wxWindow* parameter is deprecated as it does not destroy the window as would usually be expected from Remove(). You should use Detach() in new code instead. There is currently no wxSizer method that will both detach and destroy a wxWindow item.
Note
This method does not cause any layout or resizing to take place, call Layout() to update the layout "on screen" after removing a child from the sizer.
Returns
true if the child item was found and removed, false otherwise.

◆ Replace() [1/3]

virtual bool wxSizer::Replace ( size_t  index,
wxSizerItem newitem 
)
virtual

Detaches the given item at position index from the sizer and replaces it with the given wxSizerItem newitem.

The detached child is deleted only if it is a sizer or a spacer (but not if it is a wxWindow because windows are owned by their parent window, not the sizer).

This method does not cause any layout or resizing to take place, call Layout() to update the layout "on screen" after replacing a child from the sizer.

Returns true if the child item was found and removed, false otherwise.

◆ Replace() [2/3]

virtual bool wxSizer::Replace ( wxSizer oldsz,
wxSizer newsz,
bool  recursive = false 
)
virtual

Detaches the given oldsz from the sizer and replaces it with the given newsz.

The detached child sizer is deleted.

Use parameter recursive to search the given element recursively in subsizers.

This method does not cause any layout or resizing to take place, call Layout() to update the layout "on screen" after replacing a child from the sizer.

Returns true if the child item was found and removed, false otherwise.

◆ Replace() [3/3]

virtual bool wxSizer::Replace ( wxWindow oldwin,
wxWindow newwin,
bool  recursive = false 
)
virtual

Detaches the given oldwin from the sizer and replaces it with the given newwin.

The detached child window is not deleted (because windows are owned by their parent window, not the sizer).

Use parameter recursive to search the given element recursively in subsizers.

This method does not cause any layout or resizing to take place, call Layout() to update the layout "on screen" after replacing a child from the sizer.

Returns true if the child item was found and removed, false otherwise.

◆ RepositionChildren()

virtual void wxSizer::RepositionChildren ( const wxSize minSize)
pure virtual

Method which must be overridden in the derived sizer classes.

The implementation should reposition the children using the current total size available to the sizer (m_size) and the size computed by the last call to CalcMin().

Note that you should never call this method directly, call Layout() instead if you need to manually update the sizer elements positions. This method is only called by wxWidgets itself.

Since
3.1.3, before this version RecalcSizes() method not taking any arguments had to be overridden in the derived classes instead.

Implemented in wxWrapSizer, wxBoxSizer, wxStaticBoxSizer, wxGridSizer, wxFlexGridSizer, wxStdDialogButtonSizer, and wxGridBagSizer.

◆ SetContainingWindow()

void wxSizer::SetContainingWindow ( wxWindow window)

Set the window this sizer is used in.

◆ SetDimension() [1/2]

void wxSizer::SetDimension ( const wxPoint pos,
const wxSize size 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ SetDimension() [2/2]

void wxSizer::SetDimension ( int  x,
int  y,
int  width,
int  height 
)

Call this to force the sizer to take the given dimension and thus force the items owned by the sizer to resize themselves according to the rules defined by the parameter in the Add() and Prepend() methods.

◆ SetItemMinSize() [1/6]

bool wxSizer::SetItemMinSize ( size_t  index,
const wxSize size 
)

Set an item's minimum size by window, sizer, or position.

This function enables an application to set the size of an item after initial creation.

The window or sizer will be found recursively in the sizer's descendants.

See also
wxSizerItem::SetMinSize()
Returns
true if the minimal size was successfully set or false if the item was not found.

◆ SetItemMinSize() [2/6]

bool wxSizer::SetItemMinSize ( size_t  index,
int  width,
int  height 
)

Set an item's minimum size by window, sizer, or position.

This function enables an application to set the size of an item after initial creation.

The window or sizer will be found recursively in the sizer's descendants.

See also
wxSizerItem::SetMinSize()
Returns
true if the minimal size was successfully set or false if the item was not found.

◆ SetItemMinSize() [3/6]

bool wxSizer::SetItemMinSize ( wxSizer sizer,
const wxSize size 
)

Set an item's minimum size by window, sizer, or position.

This function enables an application to set the size of an item after initial creation.

The window or sizer will be found recursively in the sizer's descendants.

See also
wxSizerItem::SetMinSize()
Returns
true if the minimal size was successfully set or false if the item was not found.

◆ SetItemMinSize() [4/6]

bool wxSizer::SetItemMinSize ( wxSizer sizer,
int  width,
int  height 
)

Set an item's minimum size by window, sizer, or position.

This function enables an application to set the size of an item after initial creation.

The window or sizer will be found recursively in the sizer's descendants.

See also
wxSizerItem::SetMinSize()
Returns
true if the minimal size was successfully set or false if the item was not found.

◆ SetItemMinSize() [5/6]

bool wxSizer::SetItemMinSize ( wxWindow window,
const wxSize size 
)

Set an item's minimum size by window, sizer, or position.

This function enables an application to set the size of an item after initial creation.

The window or sizer will be found recursively in the sizer's descendants.

See also
wxSizerItem::SetMinSize()
Returns
true if the minimal size was successfully set or false if the item was not found.

◆ SetItemMinSize() [6/6]

bool wxSizer::SetItemMinSize ( wxWindow window,
int  width,
int  height 
)

Set an item's minimum size by window, sizer, or position.

This function enables an application to set the size of an item after initial creation.

The window or sizer will be found recursively in the sizer's descendants.

See also
wxSizerItem::SetMinSize()
Returns
true if the minimal size was successfully set or false if the item was not found.

◆ SetMinSize() [1/2]

void wxSizer::SetMinSize ( const wxSize size)

Call this to give the sizer a minimal size.

Normally, the sizer will calculate its minimal size based purely on how much space its children need. After calling this method GetMinSize() will return either the minimal size as requested by its children or the minimal size set here, depending on which is bigger.

◆ SetMinSize() [2/2]

void wxSizer::SetMinSize ( int  width,
int  height 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ SetSizeHints()

void wxSizer::SetSizeHints ( wxWindow window)

This method first calls Fit() and then wxTopLevelWindow::SetSizeHints() on the window passed to it.

This function is only when window is actually a wxTopLevelWindow such as a wxFrame or a wxDialog, since SetSizeHints only has any effect in these classes. It does nothing in normal windows or controls.

Note that window does not need to be the window using this sizer and it is, in fact, common to call this function on the sizer associated with the panel covering the client area of a frame passing it the frame pointer, as this has the desired effect of adjusting the frame size to the size fitting the panel, e.g.:

MyFrame::MyFrame(...) : wxFrame(...)
{
wxPanel* panel = new wxPanel(this);
wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(...);
sizer->Add(...);
panel->SetSizer(sizer);
// Use the panel sizer to set the initial and minimal size of the
// frame to fit its contents.
sizer->SetSizeHints(this);
}
The basic idea behind a box sizer is that windows will most often be laid out in rather simple basic ...
Definition: sizer.h:2019
A frame is a window whose size and position can (usually) be changed by the user.
Definition: frame.h:164
A panel is a window on which controls are placed.
Definition: panel.h:38
wxSizer is the abstract base class used for laying out subwindows in a window.
Definition: sizer.h:121
void SetSizeHints(wxWindow *window)
This method first calls Fit() and then wxTopLevelWindow::SetSizeHints() on the window passed to it.
void SetSizer(wxSizer *sizer, bool deleteOld=true)
Sets the window to have the given layout sizer.
@ wxVERTICAL
Definition: defs.h:28

This function is also used by wxWindow::SetSizerAndFit() which is commonly invoked in the constructor of wxDialog-derived classes, which don't need to use an intermediate panel, see the example in wxBoxSizer overview.

◆ SetVirtualSizeHints()

void wxSizer::SetVirtualSizeHints ( wxWindow window)

Tell the sizer to set the minimal size of the window virtual area to match the sizer's minimal size.

For windows with managed scrollbars this will set them appropriately.

Deprecated:
This is exactly the same as FitInside() in wxWidgets 2.9 and later, please replace calls to it with FitInside().
See also
wxScrolled::SetScrollbars()

◆ Show() [1/3]

bool wxSizer::Show ( size_t  index,
bool  show = true 
)

Shows the item at index.

To make a sizer item disappear or reappear, use Show() followed by Layout().

Returns true if the child item was found, false otherwise.

See also
Hide(), IsShown()

◆ Show() [2/3]

bool wxSizer::Show ( wxSizer sizer,
bool  show = true,
bool  recursive = false 
)

Shows or hides sizer.

To make a sizer item disappear or reappear, use Show() followed by Layout().

Use parameter recursive to show or hide elements found in subsizers.

Returns true if the child item was found, false otherwise.

See also
Hide(), IsShown()

◆ Show() [3/3]

bool wxSizer::Show ( wxWindow window,
bool  show = true,
bool  recursive = false 
)

Shows or hides the window.

To make a sizer item disappear or reappear, use Show() followed by Layout().

Use parameter recursive to show or hide elements found in subsizers.

Returns true if the child item was found, false otherwise.

See also
Hide(), IsShown()

◆ ShowItems()

virtual void wxSizer::ShowItems ( bool  show)
virtual

Show or hide all items managed by the sizer.