6.0.0-rc4Source

QToolBox Class

The QToolBox class provides a column of items, one of which shows its widget at a time. More…

Header#include <QToolBox>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQFrame

List of all members, including inherited members

Public Functions

QToolBox(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags())
~QToolBox()
intaddItem(QWidget *widget, const QString &text)
intinsertItem(int index, QWidget *widget, const QString &text)
voidremoveItem(int index)
voidsetItemEnabled(int index, bool enabled)
boolisItemEnabled(int index) const
voidsetItemText(int index, const QString &text)
QStringitemText(int index) const
voidsetItemToolTip(int index, const QString &toolTip)
QStringitemToolTip(int index) const
intcurrentIndex() const
QWidget *currentWidget() const
QWidget *widget(int index) const
intindexOf(const QWidget *widget) const
intcount() const

Public Slots

voidsetCurrentIndex(int index)
voidsetCurrentWidget(QWidget *widget)

Signals

voidcurrentChanged(int index)

Protected Functions

virtual voiditemInserted(int index)
virtual voiditemRemoved(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

[explicit] QToolBox::QToolBox(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags())

Constructs an empty tool box with the given parent and window flags f.

[override] 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.

[signal] 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.

[virtual, protected] void QToolBox::itemInserted(int index)

Is called after an item is inserted at index. The default implementation does nothing.

[virtual, protected] 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().

[slot] void QToolBox::setCurrentIndex(int index)

Opens the item at index and emits currentChanged(), if it is another item.

[slot] 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.