wxsizerwxsizer 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 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 add, insert, and 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. wxpython note: if you wish to create a sizer class in wxpython you should derive the class from wxpysizer in order to get python-aware capabilities for the various virtual methods. derived from
wxobject include files <wx/sizer.h> see also members
wxsizer::wxsizer
wxsizer::wxsizerwxsizer() the constructor. note that wxsizer is an abstract base class and may not be instantiated.
wxsizer::~wxsizer~wxsizer() the destructor.
wxsizer::addwxsizeritem* add(wxwindow* window, const wxsizerflags& flags) wxsizeritem* add(wxwindow* window, int proportion = 0,int flag = 0, int border = 0, wxobject* userdata = null) wxsizeritem* add(wxsizer* sizer, const wxsizerflags& flags) wxsizeritem* add(wxsizer* sizer, int proportion = 0, int flag = 0, int border = 0, wxobject* userdata = null) wxsizeritem* add(int width, int height, 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: window
sizer
width and height
proportion
flag
border
userdata
flags
wxsizer::addspacerwxsizeritem* addspacer(int size) adds non-stretchable space to the sizer. more readable way of calling add(size, size, 0).
wxsizer::addstretchspacerwxsizeritem* addstretchspacer(int prop = 1) adds stretchable space to the sizer. more readable way of calling add(0, 0, prop).
wxsizer::calcminwxsize calcmin() this method is abstract and has to be overwritten by any derived class. here, the sizer will do the actual calculation of its children minimal sizes.
wxsizer::clearvoid clear(bool delete_windows = false) detaches all children from the sizer. if delete_windows is true then child windows will also be deleted.
wxsizer::detachbool detach(wxwindow* window) bool detach(wxsizer* sizer) bool detach(size_t index) detach a child from the sizer without destroying it. window is the window to be detached, sizer is the equivalent sizer and index is the position of the child in the sizer, typically 0 for the first item. this method does not cause any layout or resizing to take place, call wxsizer::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
wxsizer::fittell the sizer to resize the window to match the sizer's minimal size. this is commonly done in the constructor of the window itself, see sample in the description of wxboxsizer. returns the new size. for a top level window this is the total window size, not client size.
wxsizer::fitinsidevoid 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 wxscrolledwindow::setscrollbars, wxsizer::setvirtualsizehints
wxsizer::getchildrenwxsizeritemlist& getchildren() returns the list of the items in this sizer. the elements of type-safe wxlist wxsizeritemlist are objects of type wxsizeritem *.
wxsizer::getcontainingwindowwxwindow * getcontainingwindow() const returns the window this sizer is used in or null if none.
wxsizer::getitemwxsizeritem * getitem(wxwindow* window, bool recursive = false) wxsizeritem * getitem(wxsizer* sizer, bool recursive = false) wxsizeritem * getitem(size_t index) finds item of the sizer which holds given window, sizer or is located in sizer at position index. use parameter recursive to search in subsizers too. returns pointer to item or null.
wxsizer::getsizewxsize getsize() returns the current size of the sizer.
wxsizer::getpositionwxpoint getposition() returns the current position of the sizer.
wxsizer::getminsizewxsize 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.
wxsizer::hidebool hide(wxwindow* window, bool recursive = false) bool hide(wxsizer* sizer, bool recursive = false) bool hide(size_t index) hides the window, sizer, or item at 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 wxsizer::isshown, wxsizer::show
wxsizer::insertwxsizeritem* insert(size_t index, wxwindow* window, const wxsizerflags& flags) wxsizeritem* insert(size_t index, wxwindow* window, int proportion = 0,int flag = 0, int border = 0, wxobject* userdata = null) wxsizeritem* insert(size_t index, wxsizer* sizer, const wxsizerflags& flags) wxsizeritem* insert(size_t index, wxsizer* sizer, int proportion = 0, int flag = 0, int border = 0, wxobject* userdata = null) wxsizeritem* 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. index
see wxsizer::add for the meaning of the other parameters.
wxsizer::insertspacerwxsizeritem* insertspacer(size_t index, int size) inserts non-stretchable space to the sizer. more readable way of calling insert(size, size, 0).
wxsizer::insertstretchspacerwxsizeritem* insertstretchspacer(size_t index, int prop = 1) inserts stretchable space to the sizer. more readable way of calling insert(0, 0, prop).
wxsizer::isshownbool isshown(wxwindow* window) const bool isshown(wxsizer* sizer) const bool isshown(size_t index) const returns true if the window, sizer, or item at index is shown. see also
wxsizer::layoutvoid 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.
wxsizer::prependwxsizeritem* prepend(wxwindow* window, const wxsizerflags& flags) wxsizeritem* prepend(wxwindow* window, int proportion = 0, int flag = 0, int border = 0, wxobject* userdata = null) wxsizeritem* prepend(wxsizer* sizer, const wxsizerflags& flags) wxsizeritem* prepend(wxsizer* sizer, int proportion = 0, int flag = 0, int border = 0, wxobject* userdata = null) wxsizeritem* prepend(int width, int height, int proportion = 0, int flag = 0, int border= 0, wxobject* userdata = null) same as wxsizer::add, but prepends the items to the beginning of the list of items (windows, subsizers or spaces) owned by this sizer.
wxsizer::prependspacerwxsizeritem* prependspacer(int size) prepends non-stretchable space to the sizer. more readable way of calling prepend(size, size, 0).
wxsizer::prependstretchspacerwxsizeritem* prependstretchspacer(int prop = 1) prepends stretchable space to the sizer. more readable way of calling prepend(0, 0, prop).
wxsizer::recalcsizesvoid recalcsizes() 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 positions and sizes.
wxsizer::removebool remove(wxwindow* window) bool remove(wxsizer* sizer) bool remove(size_t 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). sizer is the wxsizer to be removed, index is the position of the child in the sizer, e.g. 0 for the first item. this method does not cause any layout or resizing to take place, call wxsizer::layout to update the layout "on screen" after removing a child from the sizer. nb: the method taking a wxwindow* parameter is deprecated as it does not destroy the window as would usually be expected from remove. you should use wxsizer::detach in new code instead. there is currently no wxsizer method that will both detach and destroy a wxwindow item. returns true if the child item was found and removed, false otherwise.
wxsizer::replacebool replace(wxwindow* oldwin, wxwindow* newwin, bool recursive = false) bool replace(wxsizer* oldsz, wxsizer* newsz, bool recursive = false) bool remove(size_t oldindex, wxsizeritem* newitem) detaches the given oldwin, oldsz child from the sizer and replaces it with the given window, sizer, or wxsizeritem. the detached child is removed only if it is a sizer or a spacer (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 wxsizer::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.
wxsizer::setdimensionvoid 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.
wxsizer::setminsizevoid setminsize(int width, int height) void 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.
wxsizer::setitemminsizevoid setitemminsize(wxwindow* window, int width, int height) void setitemminsize(wxsizer* sizer, int width, int height) void setitemminsize(size_t index, int width, int height) set an item's minimum size by window, sizer, or position. the item will be found recursively in the sizer's descendants. this function enables an application to set the size of an item after initial creation.
wxsizer::setsizehintsvoid setsizehints(wxwindow* window) this method first calls wxsizer::fit and then setsizehints on the window passed to it. this only makes sense 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. this method is commonly invoked in the constructor of a toplevel window itself (see the sample in the description of wxboxsizer) if the toplevel window is resizable.
wxsizer::setvirtualsizehintsvoid 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. see also wxscrolledwindow::setscrollbars
wxsizer::showbool show(wxwindow* window, bool show = true, bool recursive = false) bool show(wxsizer* sizer, bool show = true, bool recursive = false) bool show(size_t index, bool show = true) shows or hides the window, sizer, or item at index. 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 wxsizer::hide, wxsizer::isshown
|