QWidgetAction 类扩展 QAction by an interface for inserting custom widgets into action based containers, such as toolbars. 更多...
继承 QAction .
QWidgetAction 类扩展 QAction by an interface for inserting custom widgets into action based containers, such as toolbars.
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 在 QToolBar , presenting a range of different zoom levels. QToolBar 提供 QToolBar.insertWidget () 作为 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.
例如:若 QWidgetAction 被添加到 QToolBar then QWidgetAction.createWidget () is called. Reimplementations of that function should create a new custom widget with the specified parent.
若动作从容器 Widget 中被移除则 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 ().
Mac OS X : If you add a widget to a menu in the application's menu bar on Mac OS X, the widget will be added and it will function but with some limitations:
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
构造动作采用 parent .
Returns the list of widgets that have been using createWidget () and are currently in use by widgets the action has been added to.
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
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.
另请参阅 deleteWidget ().
返回默认 Widget。
另请参阅 setDefaultWidget ().
widget argument has it's ownership transferred to Qt.
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 ().
另请参阅 createWidget ().
重实现自 QObject.event ().
重实现自 QObject.eventFilter ().
widget argument
释放指定 widget .
Container widgets that support actions call this function when a widget action is removed.
另请参阅 requestWidget (), deleteWidget (),和 defaultWidget ().
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
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.
另请参阅 releaseWidget (), createWidget (),和 defaultWidget ().
w argument has it's ownership transferred to Qt.
集 widget to be the default widget. The ownership is transferred to QWidgetAction . 除非 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 ().
另请参阅 defaultWidget ().