Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between QPushButton and QToolButton

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.

like image 208
KelvinS Avatar asked Jul 25 '16 19:07

KelvinS


2 Answers

QToolButton is part of a group of widgets in the QtWidgets module that is focused around QAction: QMenu, QToolBar, and so forth. QPushButton is just a button. As a result, QToolButton is much more complex under the hood than QPushButton. A (not complete) list of examples:

  • QToolButton is designed to be tightly integrated with QAction. Changing the icon, text, etc. of a tool button's default action is reflected on the button.
  • You can change the layout of the tool button contents (icon only, text only, text beside icon, text below icon).
  • QToolButton supports a "split" button type where a sidebar hot zone opens a menu instead of triggering the default action.
  • Tool buttons can be created directly in a QToolBar by adding an action, while other widgets must be explicitly added.

Also note that:

  • QToolButton has smaller default internal margins than QPushButton, reflecting that it is meant to be displayed in a tight row or grid. QPushButton is more for "Ok"/"Close" type buttons that contain text with an optional icon.
  • A QToolButton should generally have an icon. A QPushButton should always have text.
like image 109
jonspaceharper Avatar answered Sep 21 '22 00:09

jonspaceharper


From Qt doc: http://doc.qt.io/qt-5/qtoolbutton.html#details

"A tool button is a special button that provides quick-access to specific commands or options. As opposed to a normal command button, a tool button usually doesn't show a text label, but shows an icon instead."

When i want a button in the GUI simple with only an icon, I use QToolButton. But when i want a classic button, i use QPushButton.

No big differences,

like image 44
mohabouje Avatar answered Sep 20 '22 00:09

mohabouje