QToolButton Class
The QToolButton class is a small button for a command, usually with a short text or an arrow. More…
| Header | #include <QToolButton> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QAbstractButton |
List of all members, including inherited members
Public Functions
| QToolButton(QWidget *parent = nullptr) | |
| ~QToolButton() | |
| bool | autoRaise() const |
| void | setAutoRaise(bool enable) |
| Qt::ArrowType | arrowType() const |
| void | setArrowType(Qt::ArrowType type) |
| Qt::ToolButtonStyle | toolButtonStyle() const |
| QAction * | defaultAction() const |
Reimplemented Public Functions
Public Slots
| void | setToolButtonStyle(Qt::ToolButtonStyle style) |
| void | setDefaultAction(QAction *action) |
Signals
Reimplemented Protected Functions
| void | paintEvent(QPaintEvent *event) |
| void | actionEvent(QActionEvent *event) |
Detailed Description
A tool button is for a place where a push button would be too big: a row of commands, or a step in a spin control. It shows its text or an arrow, and is a push button, a toggle button if it is checkable, and with setAutoRaise() it is flat until the mouse is over it:
QToolButton *open = new QToolButton(window);
open->setText("Open");
open->setAutoRaise(true);
connect(open, &QToolButton::clicked, [] { openFile(); });
Tool buttons: a text button, a pressed one, a checked one, a disabled one, one with automatic raise, and the four arrows.

See also QPushButton and QAbstractButton.
Differences from Qt
There is no icon, so there is no setIcon() or setIconSize(), and toolButtonStyle() changes nothing; a button shows a text, or an arrow if arrowType() is not Qt::NoArrow. There is no menu (setMenu(), setPopupMode()) and no auto-repeat. The button can be reached with the Tab key, but does not take the focus when clicked, as in Qt.
Member Function Documentation
QToolButton::QToolButton(QWidget *parent = nullptr)
Constructs a tool button with the given parent. It has no text.
QToolButton::~QToolButton()
Destroys the button.
void QToolButton::actionEvent(QActionEvent *event)
Reimplements QAbstractButton::actionEvent().
Qt::ArrowType QToolButton::arrowType() const
Returns the arrow that the button shows in place of its text. The default is Qt::NoArrow.
See also setArrowType().
bool QToolButton::autoRaise() const
Returns whether the button looks flat until the mouse is over it, or it is pressed. The default is false.
See also setAutoRaise().
QAction * QToolButton::defaultAction() const
Returns the default action of the button, or nullptr.
See also setDefaultAction().
void QToolButton::paintEvent(QPaintEvent *event)
Reimplements QAbstractButton::paintEvent().
void QToolButton::setArrowType(Qt::ArrowType type)
Sets the arrow that the button shows in place of its text to type.
See also arrowType().
void QToolButton::setAutoRaise(bool enable)
Sets whether the button looks flat until the mouse is over it to enable.
See also autoRaise().
void QToolButton::setDefaultAction(QAction *action)
Makes action the default action of the button: the button takes the text, tool tip, checkable and checked state and enabled state of the action and follows their changes, and clicking the button triggers the action. The action is added to the actions of the button.
See also defaultAction() and triggered().
void QToolButton::setToolButtonStyle(Qt::ToolButtonStyle style)
Sets whether the button shows its icon, its text or both to style. Buttons have no icons in Nt, so they show their text whatever the style.
See also toolButtonStyle().
QSize QToolButton::sizeHint() const
Reimplements QAbstractButton::sizeHint().
Qt::ToolButtonStyle QToolButton::toolButtonStyle() const
Returns whether the button shows its icon, its text or both. The default is Qt::ToolButtonIconOnly.
See also setToolButtonStyle().
void QToolButton::triggered(QAction *action)
This signal is emitted when action, an action of the button such as its default action, is triggered.