QSplitter Class
The QSplitter class lets the user change the sizes of the widgets in it by dragging the bars between them. More…
| Header | #include <QSplitter> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QFrame |
List of all members, including inherited members
Public Functions
| QSplitter(QWidget *parent = nullptr) | |
| QSplitter(Qt::Orientation orientation, QWidget *parent = nullptr) | |
| ~QSplitter() | |
| void | addWidget(QWidget *widget) |
| void | insertWidget(int index, QWidget *widget) |
| int | indexOf(const QWidget *widget) const |
| QWidget * | widget(int index) const |
| int | count() const |
| Qt::Orientation | orientation() const |
| void | setOrientation(Qt::Orientation orientation) |
| QList<int> | sizes() const |
| void | setSizes(const QList<int> &list) |
| void | setStretchFactor(int index, int stretch) |
| bool | childrenCollapsible() const |
| void | setChildrenCollapsible(bool collapse) |
| void | setCollapsible(int index, bool collapse) |
| bool | isCollapsible(int index) const |
| int | handleWidth() const |
| void | setHandleWidth(int width) |
Reimplemented Public Functions
| QSize | sizeHint() const |
| QSize | minimumSizeHint() const |
Signals
| void | splitterMoved(int pos, int index) |
Reimplemented Protected Functions
| void | resizeEvent(QResizeEvent *event) |
| void | showEvent(QShowEvent *event) |
| void | changeEvent(QEvent *event) |
Detailed Description
A splitter puts its widgets side by side (Qt::Horizontal, the default) or one above the other, with a handle between each two. The user drags a handle to give one widget more room and the next less. When the splitter is resized, the widgets keep their share of its size, or the ones with a stretch factor take all the change:
QSplitter *split = new QSplitter(window);
split->addWidget(list);
split->addWidget(editor);
split->setSizes({150, 450});
split->setStretchFactor(1, 1);
A widget that is dragged to less than half of its minimum size collapses to nothing, unless it is not collapsible.
A horizontal splitter with a list and an editor, and a vertical one with two panes.

See also QScrollArea and QTabWidget.
Differences from Qt
There is no QSplitterHandle class and no handle(), replaceWidget(), saveState() or restoreState(), and no setOpaqueResize(): the widgets always follow the handle. A splitter has no refresh(). The cursor does not change over a handle.
Member Function Documentation
QSplitter::QSplitter(QWidget *parent = nullptr)
Constructs a horizontal splitter with the given parent.
QSplitter::QSplitter(Qt::Orientation orientation, QWidget *parent = nullptr)
Constructs a splitter with the given orientation and parent.
QSplitter::~QSplitter()
Destroys the splitter, and the widgets in it.
void QSplitter::addWidget(QWidget *widget)
Adds widget after the last one, and makes it a child of the splitter.
See also insertWidget().
void QSplitter::changeEvent(QEvent *event)
Reimplements QFrame::changeEvent().
bool QSplitter::childrenCollapsible() const
Returns whether the user can shrink a widget to nothing. The default is true.
See also setChildrenCollapsible() and setCollapsible().
int QSplitter::count() const
Returns the number of widgets.
int QSplitter::handleWidth() const
Returns the width of the handles: the one that setHandleWidth() set, or else the width that the style has.
See also setHandleWidth().
int QSplitter::indexOf(const QWidget *widget) const
Returns the index of widget, or -1 if it is not in the splitter.
See also widget().
void QSplitter::insertWidget(int index, QWidget *widget)
Inserts widget at index, which is brought into the range 0 to count(). A widget that is already in the splitter moves. The splitter makes widget a child of its own and shows it.
See also addWidget() and indexOf().
bool QSplitter::isCollapsible(int index) const
Returns whether the user can shrink the widget at index to nothing.
See also setCollapsible().
QSize QSplitter::minimumSizeHint() const
Reimplements QFrame::minimumSizeHint().
Qt::Orientation QSplitter::orientation() const
Returns whether the widgets are side by side (Qt::Horizontal) or one above the other (Qt::Vertical).
See also setOrientation().
void QSplitter::resizeEvent(QResizeEvent *event)
Reimplements QFrame::resizeEvent().
void QSplitter::setChildrenCollapsible(bool collapse)
Sets whether the user can shrink a widget to nothing to collapse. A widget that was set with setCollapsible() keeps what it was set to.
See also childrenCollapsible().
void QSplitter::setCollapsible(int index, bool collapse)
Sets whether the user can shrink the widget at index to nothing to collapse.
See also isCollapsible().
void QSplitter::setHandleWidth(int width)
Sets the width of the handles to width pixels.
See also handleWidth().
void QSplitter::setOrientation(Qt::Orientation orientation)
Sets whether the widgets are side by side or one above the other to orientation.
See also orientation().
void QSplitter::setSizes(const QList<int> &list)
Sets the sizes of the widgets to list. The sizes are scaled to the room there is, so that only their proportions count. A widget that has no size in the list gets 0.
See also sizes().
void QSplitter::setStretchFactor(int index, int stretch)
Gives the widget at index a stretch factor of stretch. When the splitter is resized, the widgets that have a stretch factor share the change in proportion to it, and the others keep their size. Without any, all widgets keep their share.
void QSplitter::showEvent(QShowEvent *event)
Reimplements QFrame::showEvent().
QSize QSplitter::sizeHint() const
Reimplements QFrame::sizeHint().
QList<int> QSplitter::sizes() const
Returns the sizes of the widgets along the orientation of the splitter, in pixels.
See also setSizes().
void QSplitter::splitterMoved(int pos, int index)
This signal is emitted when the user moves the handle with the given index (the first handle is 1) to pos, a position in the splitter along its orientation.
QWidget * QSplitter::widget(int index) const
Returns the widget at index, or nullptr if there is none.
See also indexOf().