QSplitter Class

The QSplitter class implements a splitter widget. More...

Header: #include <QSplitter>
qmake: QT += widgets
Inherits: QFrame

Properties

Public Functions

bool childrenCollapsible() const
int handleWidth() const
bool opaqueResize() const
Qt::Orientation orientation() const
void setChildrenCollapsible(bool)
void setHandleWidth(int)
void setOpaqueResize(bool opaque = true)
void setOrientation(Qt::Orientation)

Detailed Description

A splitter lets the user control the size of child widgets by dragging the boundary between them. Any number of widgets may be controlled by a single splitter. The typical use of a QSplitter is to create several widgets and add them using insertWidget() or addWidget().

The following example will show a QListView, QTreeView, and QTextEdit side by side, with two splitter handles:

     QSplitter *splitter = new QSplitter(parent);
     QListView *listview = new QListView;
     QTreeView *treeview = new QTreeView;
     QTextEdit *textedit = new QTextEdit;
     splitter->addWidget(listview);
     splitter->addWidget(treeview);
     splitter->addWidget(textedit);

If a widget is already inside a QSplitter when insertWidget() or addWidget() is called, it will move to the new position. This can be used to reorder widgets in the splitter later. You can use indexOf(), widget(), and count() to get access to the widgets inside the splitter.

A default QSplitter lays out its children horizontally (side by side); you can use setOrientation(Qt::Vertical) to lay its children out vertically.

By default, all widgets can be as large or as small as the user wishes, between the minimumSizeHint() (or minimumSize()) and maximumSize() of the widgets.

QSplitter resizes its children dynamically by default. If you would rather have QSplitter resize the children only at the end of a resize operation, call setOpaqueResize(false).

The initial distribution of size between the widgets is determined by multiplying the initial size with the stretch factor. You can also use setSizes() to set the sizes of all the widgets. The function sizes() returns the sizes set by the user. Alternatively, you can save and restore the sizes of the widgets from a QByteArray using saveState() and restoreState() respectively.

When you hide() a child, its space will be distributed among the other children. It will be reinstated when you show() it again.

Note: Adding a QLayout to a QSplitter is not supported (either through setLayout() or making the QSplitter a parent of the QLayout); use addWidget() instead (see example above).

See also QSplitterHandle, QHBoxLayout, QVBoxLayout, and QTabWidget.

Property Documentation

childrenCollapsible : bool

This property holds whether child widgets can be resized down to size 0 by the user

By default, children are collapsible. It is possible to enable and disable the collapsing of individual children using setCollapsible().

Access functions:

bool childrenCollapsible() const
void setChildrenCollapsible(bool)

See also setCollapsible().

handleWidth : int

This property holds the width of the splitter handles

By default, this property contains a value that depends on the user's platform and style preferences.

If you set handleWidth to 1 or 0, the actual grab area will grow to overlap a few pixels of its respective widgets.

Access functions:

int handleWidth() const
void setHandleWidth(int)

opaqueResize : bool

Returns true if widgets are resized dynamically (opaquely) while interactively moving the splitter. Otherwise returns false.

The default resize behavior is style dependent (determined by the SH_Splitter_OpaqueResize style hint). However, you can override it by calling setOpaqueResize()

Access functions:

bool opaqueResize() const
void setOpaqueResize(bool opaque = true)

See also QStyle::StyleHint.

orientation : Qt::Orientation

This property holds the orientation of the splitter

By default, the orientation is horizontal (i.e., the widgets are laid out side by side). The possible orientations are Qt::Horizontal and Qt::Vertical.

Access functions:

Qt::Orientation orientation() const
void setOrientation(Qt::Orientation)

See also QSplitterHandle::orientation().