QtBase  v6.3.1
Public Member Functions | Protected Member Functions | List of all members
QWidgetAction Class Reference

The QWidgetAction class extends QAction by an interface for inserting custom widgets into action based containers, such as toolbars. More...

#include <qwidgetaction.h>

Inheritance diagram for QWidgetAction:
Inheritance graph
[legend]
Collaboration diagram for QWidgetAction:
Collaboration graph
[legend]

Public Member Functions

 QWidgetAction (QObject *parent)
 
virtual ~QWidgetAction ()
 
void setDefaultWidget (QWidget *w)
 
QWidgetdefaultWidget () const
 
QWidgetrequestWidget (QWidget *parent)
 
void releaseWidget (QWidget *widget)
 
- Public Member Functions inherited from QAction
 QAction (QObject *parent=nullptr)
 
 QAction (const QString &text, QObject *parent=nullptr)
 
 QAction (const QIcon &icon, const QString &text, QObject *parent=nullptr)
 
 ~QAction ()
 
QList< QObject * > associatedObjects () const
 
void setActionGroup (QActionGroup *group)
 
QActionGroupactionGroup () const
 
void setIcon (const QIcon &icon)
 
QIcon icon () const
 
void setText (const QString &text)
 
QString text () const
 
void setIconText (const QString &text)
 
QString iconText () const
 
void setToolTip (const QString &tip)
 
QString toolTip () const
 
void setStatusTip (const QString &statusTip)
 
QString statusTip () const
 
void setWhatsThis (const QString &what)
 
QString whatsThis () const
 
void setPriority (Priority priority)
 
Priority priority () const
 
void setSeparator (bool b)
 
bool isSeparator () const
 
void setFont (const QFont &font)
 
QFont font () const
 
void setCheckable (bool)
 
bool isCheckable () const
 
QVariant data () const
 
void setData (const QVariant &var)
 
bool isChecked () const
 
bool isEnabled () const
 
bool isVisible () const
 
void activate (ActionEvent event)
 
void setMenuRole (MenuRole menuRole)
 
MenuRole menuRole () const
 
void setIconVisibleInMenu (bool visible)
 
bool isIconVisibleInMenu () const
 
void setShortcutVisibleInContextMenu (bool show)
 
bool isShortcutVisibleInContextMenu () const
 
bool showStatusText (QObject *object=nullptr)
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 

Protected Member Functions

virtual bool event (QEvent *) override
 
virtual bool eventFilter (QObject *, QEvent *) override
 
virtual QWidgetcreateWidget (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
QObjectsender () 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< QObjectDatad_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...
 

Detailed Description

The QWidgetAction class extends QAction by an interface for inserting custom widgets into action based containers, such as toolbars.

Since
4.2

\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

See also
QAction, QActionGroup, QWidget

Definition at line 52 of file qwidgetaction.h.

Constructor & Destructor Documentation

◆ QWidgetAction()

QWidgetAction::QWidgetAction ( QObject parent)
explicit

Constructs an action with parent.

Definition at line 110 of file qwidgetaction.cpp.

◆ ~QWidgetAction()

QWidgetAction::~QWidgetAction ( )
virtual

Destroys the object and frees allocated resources.

Definition at line 118 of file qwidgetaction.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ createdWidgets()

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

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.

Here is the caller graph for this function:

◆ createWidget()

QWidget * QWidgetAction::createWidget ( QWidget parent)
protectedvirtual

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.

See also
deleteWidget()

Reimplemented in CrashedAction, and ComboAction.

Definition at line 251 of file qwidgetaction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ defaultWidget()

QWidget * QWidgetAction::defaultWidget ( ) const

Returns the default widget.

Definition at line 158 of file qwidgetaction.cpp.

◆ deleteWidget()

void QWidgetAction::deleteWidget ( QWidget widget)
protectedvirtual

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().

See also
createWidget()

Definition at line 266 of file qwidgetaction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ event()

bool QWidgetAction::event ( QEvent event)
overrideprotectedvirtual

\reimp

Reimplemented from QAction.

Definition at line 223 of file qwidgetaction.cpp.

Here is the call graph for this function:

◆ eventFilter()

bool QWidgetAction::eventFilter ( QObject obj,
QEvent event 
)
overrideprotectedvirtual

\reimp

Reimplemented from QObject.

Definition at line 238 of file qwidgetaction.cpp.

Here is the call graph for this function:

◆ releaseWidget()

void QWidgetAction::releaseWidget ( QWidget widget)

Releases the specified widget.

Container widgets that support actions call this function when a widget action is removed.

See also
requestWidget(), deleteWidget(), defaultWidget()

Definition at line 200 of file qwidgetaction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ requestWidget()

QWidget * QWidgetAction::requestWidget ( QWidget parent)

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.

See also
releaseWidget(), createWidget(), defaultWidget()

Definition at line 173 of file qwidgetaction.cpp.

Here is the call graph for this function:

◆ setDefaultWidget()

void QWidgetAction::setDefaultWidget ( QWidget widget)

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.

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: