QtBase
v6.3.1
|
The QWidgetAction class extends QAction by an interface for inserting custom widgets into action based containers, such as toolbars. More...
#include <qwidgetaction.h>
Protected Member Functions | |
virtual bool | event (QEvent *) override |
virtual bool | eventFilter (QObject *, QEvent *) override |
virtual QWidget * | createWidget (QWidget *parent) |
virtual void | deleteWidget (QWidget *widget) |
QList< QWidget * > | createdWidgets () const |
Protected Member Functions inherited from QAction | |
QAction (QActionPrivate &dd, QObject *parent) | |
Protected Member Functions inherited from QObject | |
QObject * | sender () const |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Additional Inherited Members | |
Public Types inherited from QAction | |
enum | MenuRole { NoRole = 0 , TextHeuristicRole , ApplicationSpecificRole , AboutQtRole , AboutRole , PreferencesRole , QuitRole } |
enum | Priority { LowPriority = 0 , NormalPriority = 128 , HighPriority = 256 } |
enum | ActionEvent { Trigger , Hover } |
Public Slots inherited from QAction | |
void | trigger () |
void | hover () |
void | setChecked (bool) |
void | toggle () |
void | setEnabled (bool) |
void | resetEnabled () |
void | setDisabled (bool b) |
void | setVisible (bool) |
Public Slots inherited from QObject | |
void | deleteLater () |
Signals inherited from QAction | |
void | changed () |
void | enabledChanged (bool enabled) |
void | checkableChanged (bool checkable) |
void | visibleChanged () |
void | triggered (bool checked=false) |
void | hovered () |
void | toggled (bool) |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
Static Public Member Functions inherited from QObject | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection) |
static QMetaObject::Connection ::type | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot) |
static QMetaObject::Connection ::type | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot) |
template<typename Func1 , typename Func2 > | |
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Properties inherited from QAction | |
bool | checkable |
whether the action is a checkable action More... | |
bool | checked |
whether the action is checked. More... | |
bool | enabled |
whether the action is enabled More... | |
QIcon | icon |
the action's icon More... | |
QString | text |
the action's descriptive text More... | |
QString | iconText |
the action's descriptive icon text More... | |
QString | toolTip |
the action's tooltip More... | |
QString | statusTip |
the action's status tip More... | |
QString | whatsThis |
the action's "What's This?" help text More... | |
QFont | font |
the action's font More... | |
bool | visible |
whether the action can be seen (e.g. in menus and toolbars) More... | |
MenuRole | menuRole |
the action's menu role More... | |
bool | iconVisibleInMenu |
Whether or not an action should show an icon in a menu. More... | |
bool | shortcutVisibleInContextMenu |
Whether or not an action should show a shortcut in a context menu. More... | |
Priority | priority |
the actions's priority in the user interface. More... | |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
Related Functions inherited from QObject | |
template< class T > T | qobject_cast (const QObject *object) |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
The QWidgetAction class extends QAction by an interface for inserting custom widgets into action based containers, such as toolbars.
\inmodule QtWidgets
Most actions in an application are represented as items in menus or buttons in toolbars. However sometimes more complex widgets are necessary. For example a zoom action in a word processor may be realized using a QComboBox in a QToolBar, presenting a range of different zoom levels. QToolBar provides QToolBar::insertWidget() as convenience function for inserting a single widget. However if you want to implement an action that uses custom widgets for visualization in multiple containers then you have to subclass QWidgetAction.
If a QWidgetAction is added for example to a QToolBar then QWidgetAction::createWidget() is called. Reimplementations of that function should create a new custom widget with the specified parent.
If the action is removed from a container widget then QWidgetAction::deleteWidget() is called with the previously created custom widget as argument. The default implementation hides the widget and deletes it using QObject::deleteLater().
If you have only one single custom widget then you can set it as default widget using setDefaultWidget(). That widget will then be used if the action is added to a QToolBar, or in general to an action container that supports QWidgetAction. If a QWidgetAction with only a default widget is added to two toolbars at the same time then the default widget is shown only in the first toolbar the action was added to. QWidgetAction takes over ownership of the default widget.
Note that it is up to the widget to activate the action, for example by reimplementing mouse event handlers and calling QAction::trigger().
{\macos }: If you add a widget to a menu in the application's menu bar on \macos, the widget will be added and it will function but with some limitations: \list 1
Definition at line 52 of file qwidgetaction.h.
|
explicit |
Constructs an action with parent.
Definition at line 110 of file qwidgetaction.cpp.
|
virtual |
Destroys the object and frees allocated resources.
Definition at line 118 of file qwidgetaction.cpp.
Returns the list of widgets that have been using createWidget() and are currently in use by widgets the action has been added to.
Definition at line 276 of file qwidgetaction.cpp.
This function is called whenever the action is added to a container widget that supports custom widgets. If you don't want a custom widget to be used as representation of the action in the specified parent widget then 0 should be returned.
Reimplemented in CrashedAction, and ComboAction.
Definition at line 251 of file qwidgetaction.cpp.
QWidget * QWidgetAction::defaultWidget | ( | ) | const |
Returns the default widget.
Definition at line 158 of file qwidgetaction.cpp.
This function is called whenever the action is removed from a container widget that displays the action using a custom widget previously created using createWidget(). The default implementation hides the widget and schedules it for deletion using QObject::deleteLater().
Definition at line 266 of file qwidgetaction.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QAction.
Definition at line 223 of file qwidgetaction.cpp.
\reimp
Reimplemented from QObject.
Definition at line 238 of file qwidgetaction.cpp.
Releases the specified widget.
Container widgets that support actions call this function when a widget action is removed.
Definition at line 200 of file qwidgetaction.cpp.
Returns a widget that represents the action, with the given parent.
Container widgets that support actions can call this function to request a widget as visual representation of the action.
Definition at line 173 of file qwidgetaction.cpp.
Sets widget to be the default widget. The ownership is transferred to QWidgetAction. Unless createWidget() is reimplemented by a subclass to return a new widget the default widget is used when a container widget requests a widget through requestWidget().
Definition at line 137 of file qwidgetaction.cpp.