QWidgetAction Class
The QWidgetAction class is an action that a widget stands for in a tool bar. More…
| Header | #include <QWidgetAction> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QAction |
List of all members, including inherited members
Public Functions
| QWidgetAction(QObject *parent) | |
| ~QWidgetAction() | |
| void | setDefaultWidget(QWidget *widget) |
| QWidget * | defaultWidget() const |
| QWidget * | requestWidget(QWidget *parent) |
| void | releaseWidget(QWidget *widget) |
Protected Functions
| virtual QWidget * | createWidget(QWidget *parent) |
| virtual void | deleteWidget(QWidget *widget) |
| QList<QWidget *> | createdWidgets() const |
Detailed Description
A widget action puts a widget, such as a combo box or a slider, in a QToolBar where a button would be. Give it a default widget, which one tool bar at a time shows:
auto *zoom = new QWidgetAction(window);
zoom->setDefaultWidget(new QSlider(Qt::Horizontal));
toolBar->addAction(zoom);
To show the action in several places at once, subclass it and reimplement createWidget() to make a widget for each, and deleteWidget() if they need more than deleting.
See also QAction and QToolBar::addWidget().
Differences from Qt
Only QToolBar asks for the widgets: a widget action in a QMenu is shown as a plain entry with its text.
Member Function Documentation
QWidgetAction::QWidgetAction(QObject *parent)
Constructs a widget action with the given parent.
QWidgetAction::~QWidgetAction()
Destroys the action, its default widget and the widgets it made.
QList<QWidget *> QWidgetAction::createdWidgets() const
Returns the widgets that createWidget() made and that are in use.
QWidget * QWidgetAction::createWidget(QWidget *parent)
Is called by requestWidget() to make a widget in parent. The default implementation returns nullptr, so that the default widget is used.
QWidget * QWidgetAction::defaultWidget() const
Returns the default widget, or nullptr.
void QWidgetAction::deleteWidget(QWidget *widget)
Is called by releaseWidget() for widget, which createWidget() made. The default implementation deletes it.
void QWidgetAction::releaseWidget(QWidget *widget)
Gives back widget, which requestWidget() returned. A widget made by createWidget() goes to deleteWidget(); the default widget is hidden and kept for the next request.
QWidget * QWidgetAction::requestWidget(QWidget *parent)
Returns a widget for the action in parent: one made by createWidget(), or else the default widget if no one else uses it, or nullptr. Give it back with releaseWidget().
See also releaseWidget().
void QWidgetAction::setDefaultWidget(QWidget *widget)
Makes widget the default widget of the action, which the action owns. The default widget that it had is deleted. The default widget is shown by one tool bar at a time.
See also defaultWidget().