I'm new to Qt and the difference between QPushButton
and QToolButton
is not so clear to me.
I know that a QToolButton
is usually used in a QToolBar
and it usually shows only an icon, without text, but I don't quite understand the main difference between both.
Does it have any bigger difference?
When should I use QPushButton
and when should I use QToolButton
?
I would like to know this to use the most appropriate button, and I need to perform some GUI tests and maybe it can be relevant.
QPushButton
is simply a button. QToolButton
is part of a group of widgets in the QtWidgets module that operate on QAction
s: QMenu
and QToolBar
are other examples. As a result, QToolButton
is much more complex under the hood than QPushButton
.
Some examples of how they are different in practice:
QToolButton
is tightly integrated with QAction
. Changing the icon, text, or other properties of a tool button's default action is reflected on the button.QPushButton
.QToolButton
supports a "split" button type: a sidebar hot zone opens a menu instead of triggering the default action.QToolBar
by adding an action. Other widgets must be explicitly added to the toolbar.QPushButton
is more for "Ok"/"Close" type buttons that contain text with an optional icon.QToolButton
should generally have an icon.QPushButton
should always have text.