QToolBox Class
The QToolBox class provides a column of items, one of which shows its widget at a time. More…
| Header | #include <QToolBox> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QFrame |
List of all members, including inherited members
Public Functions
| QToolBox(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()) | |
| ~QToolBox() | |
| int | addItem(QWidget *widget, const QString &text) |
| int | insertItem(int index, QWidget *widget, const QString &text) |
| void | removeItem(int index) |
| void | setItemEnabled(int index, bool enabled) |
| bool | isItemEnabled(int index) const |
| void | setItemText(int index, const QString &text) |
| QString | itemText(int index) const |
| void | setItemToolTip(int index, const QString &toolTip) |
| QString | itemToolTip(int index) const |
| int | currentIndex() const |
| QWidget * | currentWidget() const |
| QWidget * | widget(int index) const |
| int | indexOf(const QWidget *widget) const |
| int | count() const |
Public Slots
| void | setCurrentIndex(int index) |
| void | setCurrentWidget(QWidget *widget) |
Signals
| void | currentChanged(int index) |
Protected Functions
| virtual void | itemInserted(int index) |
| virtual void | itemRemoved(int index) |
Detailed Description
Each item has a bar with a text; clicking a bar opens its item, whose widget fills the room under the bar, and closes the one that was open:
QToolBox *box = new QToolBox(window);
box->addItem(new QLabel("Brushes"), "Brushes");
box->addItem(new QLabel("Colors"), "Colors");
connect(box, &QToolBox::currentChanged, [](int index) { qDebug() << index; });
See also QTabWidget and QStackedWidget.
Differences from Qt
The items have no icons (setItemIcon()), and the change of item is not animated.
Member Function Documentation
QToolBox::QToolBox(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags())
Constructs an empty tool box with the given parent and window flags f.
QToolBox::~QToolBox()
Destroys the tool box and its widgets.
int QToolBox::addItem(QWidget *widget, const QString &text)
Adds an item with the given widget and text at the end and returns its index.
int QToolBox::count() const
Returns the number of items.
void QToolBox::currentChanged(int index)
This signal is emitted when the current item changes to the one at index, which is -1 if there are no items left.
int QToolBox::currentIndex() const
Returns the index of the current item, or -1 if there are no items.
QWidget * QToolBox::currentWidget() const
Returns the widget of the current item, or nullptr.
int QToolBox::indexOf(const QWidget *widget) const
Returns the index of the item of widget, or -1.
int QToolBox::insertItem(int index, QWidget *widget, const QString &text)
Inserts an item with the given widget and text at index, or at the end if index is out of range, and returns its index. The tool box takes the widget as a child. The first item becomes current.
See also removeItem().
bool QToolBox::isItemEnabled(int index) const
Returns whether the item at index is enabled.
void QToolBox::itemInserted(int index)
Is called after an item is inserted at index. The default implementation does nothing.
void QToolBox::itemRemoved(int index)
Is called after the item at index is removed. The default implementation does nothing.
QString QToolBox::itemText(int index) const
Returns the text of the item at index.
QString QToolBox::itemToolTip(int index) const
Returns the tool tip of the item at index.
void QToolBox::removeItem(int index)
Removes the item at index. The widget is not deleted; it stays a child of the tool box, hidden.
See also insertItem().
void QToolBox::setCurrentIndex(int index)
Opens the item at index and emits currentChanged(), if it is another item.
void QToolBox::setCurrentWidget(QWidget *widget)
Opens the item of widget.
void QToolBox::setItemEnabled(int index, bool enabled)
Enables the item at index if enabled is true, and disables it otherwise. A disabled item cannot be opened by the user; if it was current, the next enabled item becomes current.
void QToolBox::setItemText(int index, const QString &text)
Sets the text of the item at index to text.
void QToolBox::setItemToolTip(int index, const QString &toolTip)
Sets the tool tip of the bar of the item at index to toolTip.
QWidget * QToolBox::widget(int index) const
Returns the widget of the item at index, or nullptr.