CopperSpice API
1.9.1
|
Used to add custom widgets for classes like a QToolbar which support actions. More...
Public Methods | |
QWidgetAction (QObject *parent) | |
virtual | ~QWidgetAction () |
QWidget * | defaultWidget () const |
void | releaseWidget (QWidget *widget) |
QWidget * | requestWidget (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 () | |
QActionGroup * | actionGroup () 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 |
QMenu * | menu () const |
MenuRole | menuRole () const |
QWidget * | parentWidget () 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< QKeySequence > | shortcuts () 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< QString > | dynamicPropertyNames () const |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, 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 QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | 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) |
QThread * | thread () const |
Protected Methods | |
QList< QWidget * > | createdWidgets () const |
virtual QWidget * | createWidget (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 QMetaObject & | staticMetaObject () |
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 | |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
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.
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().
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.
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.
|
explicit |
Constructs a QWidgetAction with parent.
|
virtual |
Destroys the QWidgetAction and frees allocated resources.
Returns the list of widgets which have been created using createWidget() and are currently in use.
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.
QWidget * QWidgetAction::defaultWidget | ( | ) | const |
Returns the default QWidget.
|
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().
|
overrideprotectedvirtual |
Reimplemented from QAction::event()
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.
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().
void QWidgetAction::setDefaultWidget | ( | QWidget * | widget | ) |
Sets widget as the default widget. The ownership of the QWidget is transferred to QWidgetAction.