CopperSpice API  1.9.1
QWidgetAction Class Reference

Used to add custom widgets for classes like a QToolbar which support actions. More...

Inheritance diagram for QWidgetAction:
QAction QObject

Public Methods

 QWidgetAction (QObject *parent)
 
virtual ~QWidgetAction ()
 
QWidgetdefaultWidget () const
 
void releaseWidget (QWidget *widget)
 
QWidgetrequestWidget (QWidget *parent)
 
void setDefaultWidget (QWidget *widget)
 
- Public Methods inherited from QAction
 QAction (const QIcon &icon, const QString &text, QObject *parent)
 
 QAction (const QString &text, QObject *parent)
 
 QAction (QObject *parent)
 
 ~QAction ()
 
QActionGroupactionGroup () const
 
void activate (ActionEvent event)
 
QList< QGraphicsWidget * > associatedGraphicsWidgets () const
 
QList< QWidget * > associatedWidgets () const
 
bool autoRepeat () const
 
QVariant data () const
 
QFont font () const
 
QIcon icon () const
 
QString iconText () const
 
bool isCheckable () const
 
bool isChecked () const
 
bool isEnabled () const
 
bool isIconVisibleInMenu () const
 
bool isSeparator () const
 
bool isVisible () const
 
QMenumenu () const
 
MenuRole menuRole () const
 
QWidgetparentWidget () const
 
Priority priority () const
 
void setActionGroup (QActionGroup *group)
 
void setAutoRepeat (bool repeat)
 
void setCheckable (bool isChecked)
 
void setData (const QVariant &data)
 
void setFont (const QFont &font)
 
void setIcon (const QIcon &icon)
 
void setIconText (const QString &text)
 
void setIconVisibleInMenu (bool visible)
 
void setMenu (QMenu *menu)
 
void setMenuRole (MenuRole menuRole)
 
void setPriority (Priority priority)
 
void setSeparator (bool separator)
 
void setShortcut (const QKeySequence &shortcut)
 
void setShortcutContext (Qt::ShortcutContext context)
 
void setShortcuts (const QList< QKeySequence > &shortcuts)
 
void setShortcuts (QKeySequence::StandardKey key)
 
void setStatusTip (const QString &statusTip)
 
void setText (const QString &text)
 
void setToolTip (const QString &tooltip)
 
void setWhatsThis (const QString &what)
 
QKeySequence shortcut () const
 
Qt::ShortcutContext shortcutContext () const
 
QList< QKeySequenceshortcuts () const
 
bool showStatusText (QWidget *widget=nullptr)
 
QString statusTip () const
 
QString text () const
 
QString toolTip () const
 
QString whatsThis () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Protected Methods

QList< QWidget * > createdWidgets () const
 
virtual QWidgetcreateWidget (QWidget *parent)
 
virtual void deleteWidget (QWidget *widget)
 
bool event (QEvent *event) override
 
bool eventFilter (QObject *object, QEvent *event) override
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Friends

class QToolBar
 

Additional Inherited Members

- Public Types inherited from QAction
enum  ActionEvent
 
enum  MenuRole
 
enum  Priority
 
- Public Signals inherited from QAction
void changed ()
 
void hovered ()
 
void toggled (bool isChecked)
 
void triggered (bool isChecked=false)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 
- Public Slots inherited from QAction
void hover ()
 
void setChecked (bool isChecked)
 
void setDisabled (bool disabled)
 
void setEnabled (bool enabled)
 
void setVisible (bool visible)
 
void toggle ()
 
void trigger ()
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Properties inherited from QAction
 autoRepeat
 
 checkable
 
 checked
 
 enabled
 
 font
 
 icon
 
 iconText
 
 iconVisibleInMenu
 
 menuRole
 
 priority
 
 shortcut
 
 shortcutContext
 
 statusTip
 
 text
 
 toolTip
 
 visible
 
 whatsThis
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The QWidgetAction class is used to add custom widgets for classes like QToolBar, QMenu, and QLineEdit which support actions. This class inherits from QAction and extends its functionality.

Actions using Custom Widgets

Most actions in an application are represented as items in menus or buttons on toolbars. Sometimes more complex widgets are necessary. For example, it might be nice to have a QAction which shows a range of different zoom levels on the toolbar of text editor. One way to implement this option is by adding a QComboBox directly on the QToolBar. Using this approach does not add a QAction on the QToolBar.

To use a custom widget with a QAction you will need to inherit from QWidgetAction. As an example, to add a QWidgetAction to a QToolBar override createWidget() which returns a QWidget. Your implementation of this method should create a new custom widget.

If the QWidgetAction is removed from the toolbar then QWidgetAction::deleteWidget() will be called. The default implementation hides the widget and deletes it using QObject::deleteLater().

Default Actions

If there is only one custom widget, it can be set as the default using setDefaultWidget(). Having a default widget can be easier since you will not need to inherit from QWidgetAction and override the createWidget() method. The default widget can be displayed on the QToolBar and when the user clicks on the widget the associated QWidgetAction will be triggered.

QWidgetAction will take over ownership of the default widget. It is up to the widget to activate the action, for example by reimplementing mouse event handlers and calling QAction::trigger().

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.

Mac OS X

If you add a widget to a menu in the applications menu bar on Mac OS X the widget will be added however it will function with some limitations.

  1. Widget is reparented away from the QMenu to the native menu view. If you show the menu in some other place like a popup menu, the widget will not be there.
  2. Focus and Keyboard handling of the widget is not possible.
  3. Due to the design of Apple mouse tracking on the widget currently does not work.
  4. Connecting the triggered() signal to a slot which opens a modal dialog will cause a crash in Mac OS X 10.4 (known bug acknowledged by Apple), a workaround is to use a QueuedConnection instead of a DirectConnection.
See also
QAction, QActionGroup, QWidget

Constructor & Destructor Documentation

QWidgetAction::QWidgetAction ( QObject parent)
explicit

Constructs a QWidgetAction with parent.

QWidgetAction::~QWidgetAction ( )
virtual

Destroys the QWidgetAction and frees allocated resources.

Method Documentation

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

Returns the list of widgets which have been created using createWidget() and are currently in use.

QWidget * QWidgetAction::createWidget ( QWidget parent)
protectedvirtual

This method is called when a QWidgetAction is added to a widget like QToolBar, which supports custom widgets.

You will need to inherit from QWidgetAction and override this method. If you do not want a custom widget to be used for some specified parent widget then a nullptr should be returned. The default implementation returns a nullptr.

See also
deleteWidget()
QWidget * QWidgetAction::defaultWidget ( ) const

Returns the default QWidget.

See also
setDefaultWidget()
void QWidgetAction::deleteWidget ( QWidget widget)
protectedvirtual

This method is called when the QWidgetAction is removed from a widget like a QToolBar. The given widget is the one previously created using createWidget(). The default implementation hides the widget and schedules it for deletion using QObject::deleteLater().

See also
createWidget()
bool QWidgetAction::event ( QEvent event)
overrideprotectedvirtual

Reimplemented from QAction::event()

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

Reimplemented from QObject::eventFilter()

void QWidgetAction::releaseWidget ( QWidget widget)

Releases the specified widget. Widgets like QToolbar need to call this method when a QWidgetAction is removed.

See also
defaultWidget(), deleteWidget(), requestWidget()
QWidget * QWidgetAction::requestWidget ( QWidget parent)

This method is called when a QWidgetAction is added to a widget like QToolBar, which supports custom widgets. Calls createWidget() and if it returns a nullptr this method will call defaultWidget().

See also
createWidget(), defaultWidget(), releaseWidget()
void QWidgetAction::setDefaultWidget ( QWidget widget)

Sets widget as the default widget. The ownership of the QWidget is transferred to QWidgetAction.

See also
defaultWidget()