• PySide 模块
  • PySide.QtGui
  • 内容表

    上一话题

    QAction

    下一话题

    QSyntaxHighlighter

    QWidgetAction

    概要

    虚函数

    详细描述

    PySide.QtGui.QWidgetAction class extends PySide.QtGui.QAction 通过界面 (把自定义 Widget 插入基于动作的容器,譬如:工具栏)。

    应用程序中的大多数动作被表示成菜单项或工具栏按钮。不管怎样,更复杂的 Widget 有时是必要的。例如,文字处理程序缩放动作可以被变现使用 PySide.QtGui.QComboBox PySide.QtGui.QToolBar ,呈现不同缩放级别的范围。 PySide.QtGui.QToolBar 提供 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 PySide.QtGui.QWidgetAction .

    PySide.QtGui.QWidgetAction is added for example to a PySide.QtGui.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 PySide.QtGui.QWidgetAction.setDefaultWidget() . That widget will then be used if the action is added to a PySide.QtGui.QToolBar , or in general to an action container that supports PySide.QtGui.QWidgetAction . If a PySide.QtGui.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. PySide.QtGui.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:

    class PySide.QtGui. QWidgetAction ( parent )
    参数: parent PySide.QtCore.QObject

    构造动作采用 parent .

    PySide.QtGui.QWidgetAction. createWidget ( parent )
    参数: parent PySide.QtGui.QWidget
    返回类型: PySide.QtGui.QWidget

    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.

    PySide.QtGui.QWidgetAction. createdWidgets ( )
    返回类型:

    Returns the list of widgets that have been using PySide.QtGui.QWidgetAction.createWidget() and are currently in use by widgets the action has been added to.

    PySide.QtGui.QWidgetAction. defaultWidget ( )
    返回类型: PySide.QtGui.QWidget

    返回默认 Widget。

    PySide.QtGui.QWidgetAction. deleteWidget ( widget )
    参数: widget PySide.QtGui.QWidget

    This function is called whenever the action is removed from a container widget that displays the action using a custom widget previously created using PySide.QtGui.QWidgetAction.createWidget() . The default implementation hides the widget and schedules it for deletion using QObject.deleteLater() .

    PySide.QtGui.QWidgetAction. releaseWidget ( widget )
    参数: widget PySide.QtGui.QWidget

    释放指定 widget .

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

    PySide.QtGui.QWidgetAction. requestWidget ( parent )
    参数: parent PySide.QtGui.QWidget
    返回类型: PySide.QtGui.QWidget

    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.

    PySide.QtGui.QWidgetAction. setDefaultWidget ( w )
    参数: w PySide.QtGui.QWidget

    widget to be the default widget. The ownership is transferred to PySide.QtGui.QWidgetAction . Unless PySide.QtGui.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 PySide.QtGui.QWidgetAction.requestWidget() .