6.0.0-rc4Source

QWidgetAction Class

The QWidgetAction class is an action that a widget stands for in a tool bar. More…

Header#include <QWidgetAction>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQAction

List of all members, including inherited members

Public Functions

Protected Functions

virtual QWidget *createWidget(QWidget *parent)
virtual voiddeleteWidget(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

[explicit] QWidgetAction::QWidgetAction(QObject *parent)

Constructs a widget action with the given parent.

[override] QWidgetAction::~QWidgetAction()

Destroys the action, its default widget and the widgets it made.

[protected] QList<QWidget *> QWidgetAction::createdWidgets() const

Returns the widgets that createWidget() made and that are in use.

[virtual, protected] 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.

[virtual, protected] 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().