QToolButton is a class in the Qt Framework library for C++ which provides a clickable button with customizable features such as icons, text, and pop-up menus. QToolButton is used to create button components in Qt applications to perform specific actions or to display pop-up menus.
Example 1: Creating a QToolButton with an icon
#include #include
QToolButton *toolButton = new QToolButton(); toolButton->setIcon(QIcon(":/images/icon.png"));
In this example, a QToolButton is created and an image icon is set using the QIcon class.
Example 2: Adding Text to QToolButton
#include
QToolButton *toolButton = new QToolButton(); toolButton->setText("Click me!");
Here, QToolButton is created and text is added to it using the setText function.
Example 3: Using Menu with QToolButton
#include #include
QToolButton *toolButton = new QToolButton(); QMenu *menu = new QMenu(); menu->addAction("Menu item 1"); menu->addAction("Menu item 2"); toolButton->setMenu(menu); toolButton->setPopupMode(QToolButton::InstantPopup);
In this example, a QToolButton is created with a custom menu added using QMenu class. Finally, the setPopupMode function is used to display the menu when the button is clicked.
Package Library:
Qt Framework (QtWidget module)
C++ (Cpp) QToolButton - 30 examples found. These are the top rated real world C++ (Cpp) examples of QToolButton extracted from open source projects. You can rate examples to help us improve the quality of examples.