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

    上一话题

    QActionGroup

    下一话题

    QWidgetAction

    QAction

    继承者: QWidgetAction

    概要

    函数

    信号

    详细描述

    PySide.QtGui.QAction class provides an abstract user interface action that can be inserted into widgets.

    在应用程序中,许多常见命令可以凭借菜单、工具栏按钮及键盘快捷键援引。由于用户期望每个命令以相同方式履行,不管所用用户界面,它是有用的将每个命令表示成 action .

    动作可以被添加到菜单和工具栏,并自动保持同步。例如,在单词处理程序中,若用户按下加粗工具栏按钮,加粗菜单项将被自动选中。

    可以将动作创建成独立对象,但也可以在构造菜单期间创建; PySide.QtGui.QMenu 类包含用于创建适合用作菜单项的动作的方便函数。

    A PySide.QtGui.QAction may contain an icon, menu text, a shortcut, status text, “What's This?” text, and a tooltip. Most of these can be set in the constructor. They can also be set independently with PySide.QtGui.QAction.setIcon() , PySide.QtGui.QAction.setText() , PySide.QtGui.QAction.setIconText() , PySide.QtGui.QAction.setShortcut() , PySide.QtGui.QAction.setStatusTip() , PySide.QtGui.QAction.setWhatsThis() ,和 PySide.QtGui.QAction.setToolTip() . For menu items, it is possible to set an individual font with PySide.QtGui.QAction.setFont() .

    动作被添加到 Widget 使用 QWidget.addAction() or QGraphicsWidget.addAction() . Note that an action must be added to a widget before it can be used; this is also true when the shortcut should be global (i.e., Qt.ApplicationShortcut as Qt.ShortcutContext ).

    一旦 PySide.QtGui.QAction has been created it should be added to the relevant menu and toolbar, then connected to the slot which will perform the action. For example:

    openAct =  QAction(QIcon(":/images/open.png"), tr("&Open..."), self)
    openAct.setShortcuts(QKeySequence.Open)
    openAct.setStatusTip(tr("Open an existing file"))
    connect(openAct, SIGNAL("triggered()"), self, SLOT("open()"))
    fileMenu.addAction(openAct)
    fileToolBar.addAction(openAct)
    										

    推荐将动作创建作为在其中使用它们的窗口子级。在大多数情况下,动作将是应用程序主窗口的子级。

    另请参阅

    PySide.QtGui.QMenu PySide.QtGui.QToolBar 应用程序范例

    class PySide.QtGui. QAction ( parent )
    class PySide.QtGui. QAction ( icon , text , parent )
    class PySide.QtGui. QAction ( text , parent )
    参数:

    构造动作采用 parent 。若 parent 是动作组,动作会被自动插入组中。

    构造动作采用 icon 和一些 text and parent 。若 parent 是动作组,动作会被自动插入组中。

    The action uses a stripped version of text (e.g. “&Menu Option...” becomes “Menu Option”) as descriptive text for tool buttons. You can override this by setting a specific description with PySide.QtGui.QAction.setText() . The same text will be used for tooltips unless you specify a different text using PySide.QtGui.QAction.setToolTip() .

    构造动作采用一些 text and parent 。若 parent 是动作组,动作会被自动插入组中。

    The action uses a stripped version of text (e.g. “&Menu Option...” becomes “Menu Option”) as descriptive text for tool buttons. You can override this by setting a specific description with PySide.QtGui.QAction.setText() . The same text will be used for tooltips unless you specify a different text using PySide.QtGui.QAction.setToolTip() .

    PySide.QtGui.QAction. Priority

    此枚举定义用户界面中动作的优先级。

    常量 描述
    QAction.LowPriority 动作不应该在用户界面中被优先。
    QAction.NormalPriority  
    QAction.HighPriority 动作应该在用户界面中被优先。

    注意

    该枚举在 Qt 4.6 引入或被修改

    PySide.QtGui.QAction. ActionEvent

    使用此枚举类型当调用 QAction.activate()

    常量 描述
    QAction.Trigger 这将导致 QAction.triggered() signal to be emitted.
    QAction.Hover 这将导致 QAction.hovered() signal to be emitted.
    PySide.QtGui.QAction. SoftKeyRole

    This enum describes how an action should be placed in the softkey bar. Currently this enum only has an effect on the Symbian platform.

    常量 描述
    QAction.NoSoftKey This action should not be used as a softkey
    QAction.PositiveSoftKey This action is used to describe a softkey with a positive or non-destructive role such as Ok, Select, or Options.
    QAction.NegativeSoftKey This action is used to describe a soft ey with a negative or destructive role role such as Cancel, Discard, or Close.
    QAction.SelectSoftKey This action is used to describe a role that selects a particular item or widget in the application.

    Actions with a softkey role defined are only visible in the softkey bar when the widget containing the action has focus. If no widget currently has focus, the softkey framework will traverse up the widget parent hierarchy looking for a widget containing softkey actions.

    注意

    该枚举在 Qt 4.6 引入或被修改

    PySide.QtGui.QAction. MenuRole

    This enum describes how an action should be moved into the application menu on Mac OS X.

    常量 描述
    QAction.NoRole 此动作不应放入应用程序菜单中
    QAction.TextHeuristicRole This action should be put in the application menu based on the action's text as described in the PySide.QtGui.QMenuBar 文档编制。
    QAction.ApplicationSpecificRole This action should be put in the application menu with an application specific role
    QAction.AboutQtRole This action matches handles the “About Qt” menu item.
    QAction.AboutRole This action should be placed where the “About” menu item is in the application menu. The text of the menu item will be set to “About <application name>”. The application name is fetched from the Info.plist file in the application's bundle (See Deploying an Application on Mac OS X ).
    QAction.PreferencesRole This action should be placed where the “Preferences...” menu item is in the application menu.
    QAction.QuitRole This action should be placed where the Quit menu item is in the application menu.

    Setting this value only has effect on items that are in the immediate menus of the menubar, not the submenus of those menus. For example, if you have File menu in your menubar and the File menu has a submenu, setting the QAction.MenuRole for the actions in that submenu have no effect. They will never be moved.

    PySide.QtGui.QAction. actionGroup ( )
    返回类型: PySide.QtGui.QActionGroup

    返回此动作的动作组。返回 0 若没有动作组管理此动作。

    PySide.QtGui.QAction. activate ( event )
    参数: event PySide.QtGui.QAction.ActionEvent

    发送相关信号为 QAction.ActionEvent event .

    基于动作的 Widget 使用此 API 以促使 PySide.QtGui.QAction 去发射信号及发射它们自己。

    PySide.QtGui.QAction. associatedGraphicsWidgets ( )
    返回类型:

    返回已添加此动作的小部件列表。

    PySide.QtGui.QAction. associatedWidgets ( )
    返回类型:

    返回已添加此动作的小部件列表。

    PySide.QtGui.QAction. autoRepeat ( )
    返回类型: PySide.QtCore.bool

    This property holds whether the action can auto repeat.

    若为 true,动作会自动重复当按下键盘快捷方式组合时,前提是系统启用了键盘自动重复。默认值为 true。

    PySide.QtGui.QAction. changed ( )
    PySide.QtGui.QAction. data ( )
    返回类型: object

    Returns the user data as set in QAction::setData.

    PySide.QtGui.QAction. font ( )
    返回类型: PySide.QtGui.QFont

    This property holds the action's font.

    字体特性用于渲染文本设置在 PySide.QtGui.QAction 。字体被认为是提示,因为在所有情况下都不会基于应用程序和样式咨询字体。

    默认情况下,此特性包含应用程序默认字体。

    PySide.QtGui.QAction. hover ( )

    这是调用 activate(Hover) 的方便槽。

    PySide.QtGui.QAction. hovered ( )
    PySide.QtGui.QAction. icon ( )
    返回类型: PySide.QtGui.QIcon

    This property holds the action's icon.

    在工具栏中,图标被用作工具按钮图标;在菜单中,它显示在菜单文本左侧。不存在默认图标。

    On Symbian the icons which are passed to softkeys, i.e. to actions with softkey role, need to have pixmap alpha channel correctly set otherwise drawing artifacts will appear when softkey is pressed down.

    若 null 图标 ( QIcon.isNull() is passed into this function, the icon of the action is cleared.

    PySide.QtGui.QAction. iconText ( )
    返回类型: unicode

    This property holds the action's descriptive icon text.

    QToolBar.toolButtonStyle is set to a value that permits text to be displayed, the text defined held in this property appears as a label in the relevant tool button.

    It also serves as the default text in menus and tooltips if the action has not been defined with PySide.QtGui.QAction.setText() or PySide.QtGui.QAction.setToolTip() , and will also be used in toolbar buttons if no icon has been defined using PySide.QtGui.QAction.setIcon() .

    若未明确设置图标文本,动作的正常文本将用于图标文本。

    默认情况下,此特性包含空字符串。

    PySide.QtGui.QAction. isCheckable ( )
    返回类型: PySide.QtCore.bool

    This property holds whether the action is a checkable action.

    A checkable action is one which has an on/off state. For example, in a word processor, a Bold toolbar button may be either on or off. An action which is not a toggle action is a command action; a command action is simply executed, e.g. file save. By default, this property is false.

    In some situations, the state of one toggle action should depend on the state of others. For example, “Left Align”, “Center” and “Right Align” toggle actions are mutually exclusive. To achieve exclusive toggling, add the relevant toggle actions to a PySide.QtGui.QActionGroup 采用 QActionGroup.exclusive property set to true.

    PySide.QtGui.QAction. isChecked ( )
    返回类型: PySide.QtCore.bool

    This property holds whether the action is checked..

    仅可复选动作可以被复选。默认情况下,这为 false (动作未被复选)。

    另请参阅

    checkable()

    PySide.QtGui.QAction. isEnabled ( )
    返回类型: PySide.QtCore.bool

    This property holds whether the action is enabled.

    Disabled actions cannot be chosen by the user. They do not disappear from menus or toolbars, but they are displayed in a way which indicates that they are unavailable. For example, they might be displayed using only shades of gray.

    What's This? help on disabled actions is still available, provided that the QAction.whatsThis property is set.

    An action will be disabled when all widgets to which it is added (with QWidget.addAction() ) are disabled or not visible. When an action is disabled, it is not possible to trigger it through its shortcut.

    By default, this property is true (actions are enabled).

    PySide.QtGui.QAction. isIconVisibleInMenu ( )
    返回类型: PySide.QtCore.bool

    This property holds Whether or not an action should show an icon in a menu.

    In some applications, it may make sense to have actions with icons in the toolbar, but not in menus. If true, the icon (if valid) is shown in the menu, when it is false, it is not shown.

    The default is to follow whether the Qt.AA_DontShowIconsInMenus attribute is set for the application. Explicitly settings this property overrides the presence (or abscence) of the attribute.

    例如:

    app = QApplication(argv)
    app.setAttribute(Qt.AA_DontShowIconsInMenus)  # Icons are *no longer shown* in menus
    // ...
    myAction = QAction()
    // ...
    myAction.setIcon(SomeIcon)
    myAction.setIconVisibleInMenu(True)   # Icon *will* be shown in menus for *this* action.
    										

    另请参阅

    QAction.icon QApplication.setAttribute()

    PySide.QtGui.QAction. isSeparator ( )
    返回类型: PySide.QtCore.bool

    Returns true if this action is a separator action; otherwise it returns false.

    PySide.QtGui.QAction. isVisible ( )
    返回类型: PySide.QtCore.bool

    This property holds whether the action can be seen (e.g. in menus and toolbars).

    visible is true the action can be seen (e.g. in menus and toolbars) and chosen by the user; if visible is false the action cannot be seen or chosen by the user.

    Actions which are not visible are not grayed out; they do not appear at all.

    By default, this property is true (actions are visible).

    PySide.QtGui.QAction. menu ( )
    返回类型: PySide.QtGui.QMenu

    返回由此动作包含的菜单。包含菜单的动作可以被用于创建带子菜单的菜单项,或被插入工具栏中以创建带弹出菜单的按钮。

    PySide.QtGui.QAction. menuRole ( )
    返回类型: PySide.QtGui.QAction.MenuRole

    This property holds the action's menu role.

    This indicates what role the action serves in the application menu on Mac OS X. By default all action have the TextHeuristicRole , which means that the action is added based on its text (see PySide.QtGui.QMenuBar for more information).

    The menu role can only be changed before the actions are put into the menu bar in Mac OS X (usually just before the first application window is shown).

    PySide.QtGui.QAction. parentWidget ( )
    返回类型: PySide.QtGui.QWidget

    返回父级 Widget。

    PySide.QtGui.QAction. priority ( )
    返回类型: PySide.QtGui.QAction.Priority

    This property holds the actions's priority in the user interface..

    可以设置此特性以指示动作在用户界面中的优先级应该如何。

    对于实例,当工具栏拥有 Qt.ToolButtonTextBesideIcon 模式设置,那么动作具有 LowPriority 被不展示文本标签。

    PySide.QtGui.QAction. setActionGroup ( group )
    参数: group PySide.QtGui.QActionGroup

    把此动作组设为 group 。动作会被自动添加到组的动作列表。

    组内动作将是相互排斥的。

    PySide.QtGui.QAction. setAutoRepeat ( arg__1 )
    参数: arg__1 PySide.QtCore.bool

    This property holds whether the action can auto repeat.

    若为 true,动作会自动重复当按下键盘快捷方式组合时,前提是系统启用了键盘自动重复。默认值为 true。

    PySide.QtGui.QAction. setCheckable ( arg__1 )
    参数: arg__1 PySide.QtCore.bool

    This property holds whether the action is a checkable action.

    A checkable action is one which has an on/off state. For example, in a word processor, a Bold toolbar button may be either on or off. An action which is not a toggle action is a command action; a command action is simply executed, e.g. file save. By default, this property is false.

    In some situations, the state of one toggle action should depend on the state of others. For example, “Left Align”, “Center” and “Right Align” toggle actions are mutually exclusive. To achieve exclusive toggling, add the relevant toggle actions to a PySide.QtGui.QActionGroup 采用 QActionGroup.exclusive property set to true.

    PySide.QtGui.QAction. setChecked ( arg__1 )
    参数: arg__1 PySide.QtCore.bool

    This property holds whether the action is checked..

    仅可复选动作可以被复选。默认情况下,这为 false (动作未被复选)。

    另请参阅

    checkable()

    PySide.QtGui.QAction. setData ( var )
    参数: var – object

    把动作的内部数据设为给定 userData .

    PySide.QtGui.QAction. setDisabled ( b )
    参数: b PySide.QtCore.bool

    这是方便函数,为 enabled() property, that is useful for signals–slots connections. If b is true the action is disabled; otherwise it is enabled.

    PySide.QtGui.QAction. setEnabled ( arg__1 )
    参数: arg__1 PySide.QtCore.bool

    This property holds whether the action is enabled.

    Disabled actions cannot be chosen by the user. They do not disappear from menus or toolbars, but they are displayed in a way which indicates that they are unavailable. For example, they might be displayed using only shades of gray.

    What's This? help on disabled actions is still available, provided that the QAction.whatsThis property is set.

    An action will be disabled when all widgets to which it is added (with QWidget.addAction() ) are disabled or not visible. When an action is disabled, it is not possible to trigger it through its shortcut.

    By default, this property is true (actions are enabled).

    PySide.QtGui.QAction. setFont ( font )
    参数: font PySide.QtGui.QFont

    This property holds the action's font.

    字体特性用于渲染文本设置在 PySide.QtGui.QAction 。字体被认为是提示,因为在所有情况下都不会基于应用程序和样式咨询字体。

    默认情况下,此特性包含应用程序默认字体。

    PySide.QtGui.QAction. setIcon ( icon )
    参数: icon PySide.QtGui.QIcon

    This property holds the action's icon.

    在工具栏中,图标被用作工具按钮图标;在菜单中,它显示在菜单文本左侧。不存在默认图标。

    On Symbian the icons which are passed to softkeys, i.e. to actions with softkey role, need to have pixmap alpha channel correctly set otherwise drawing artifacts will appear when softkey is pressed down.

    若 null 图标 ( QIcon.isNull() is passed into this function, the icon of the action is cleared.

    PySide.QtGui.QAction. setIconText ( text )
    参数: text – unicode

    This property holds the action's descriptive icon text.

    QToolBar.toolButtonStyle is set to a value that permits text to be displayed, the text defined held in this property appears as a label in the relevant tool button.

    It also serves as the default text in menus and tooltips if the action has not been defined with PySide.QtGui.QAction.setText() or PySide.QtGui.QAction.setToolTip() , and will also be used in toolbar buttons if no icon has been defined using PySide.QtGui.QAction.setIcon() .

    若未明确设置图标文本,动作的正常文本将用于图标文本。

    默认情况下,此特性包含空字符串。

    PySide.QtGui.QAction. setIconVisibleInMenu ( visible )
    参数: visible PySide.QtCore.bool

    This property holds Whether or not an action should show an icon in a menu.

    In some applications, it may make sense to have actions with icons in the toolbar, but not in menus. If true, the icon (if valid) is shown in the menu, when it is false, it is not shown.

    The default is to follow whether the Qt.AA_DontShowIconsInMenus attribute is set for the application. Explicitly settings this property overrides the presence (or abscence) of the attribute.

    例如:

    app = QApplication(argv)
    app.setAttribute(Qt.AA_DontShowIconsInMenus)  # Icons are *no longer shown* in menus
    // ...
    myAction = QAction()
    // ...
    myAction.setIcon(SomeIcon)
    myAction.setIconVisibleInMenu(True)   # Icon *will* be shown in menus for *this* action.
    										

    另请参阅

    QAction.icon QApplication.setAttribute()

    PySide.QtGui.QAction. setMenu ( menu )
    参数: menu PySide.QtGui.QMenu

    把由此动作包含的菜单设为指定 menu .

    PySide.QtGui.QAction. setMenuRole ( menuRole )
    参数: menuRole PySide.QtGui.QAction.MenuRole

    This property holds the action's menu role.

    This indicates what role the action serves in the application menu on Mac OS X. By default all action have the TextHeuristicRole , which means that the action is added based on its text (see PySide.QtGui.QMenuBar for more information).

    The menu role can only be changed before the actions are put into the menu bar in Mac OS X (usually just before the first application window is shown).

    PySide.QtGui.QAction. setPriority ( priority )
    参数: priority PySide.QtGui.QAction.Priority

    This property holds the actions's priority in the user interface..

    可以设置此特性以指示动作在用户界面中的优先级应该如何。

    对于实例,当工具栏拥有 Qt.ToolButtonTextBesideIcon 模式设置,那么动作具有 LowPriority 被不展示文本标签。

    PySide.QtGui.QAction. setSeparator ( b )
    参数: b PySide.QtCore.bool

    b 为 true,则此动作将被认为是分隔符。

    如何表示分隔符从属插入其的 Widget。在大多数情况下,文本、子菜单及图标会被分隔符动作忽略。

    PySide.QtGui.QAction. setShortcut ( shortcut )
    参数: shortcut PySide.QtGui.QKeySequence

    This property holds the action's primary shortcut key.

    此特性的有效键码可以找到,在 Qt.Key and Qt.Modifier 。没有默认的快捷键。

    PySide.QtGui.QAction. setShortcutContext ( context )
    参数: context PySide.QtCore.Qt.ShortcutContext

    This property holds the context for the action's shortcut.

    可以找到此特性的有效值在 Qt.ShortcutContext 。默认值为 Qt.WindowShortcut .

    PySide.QtGui.QAction. setShortcuts ( arg__1 )
    参数: arg__1 PySide.QtGui.QKeySequence.StandardKey
    PySide.QtGui.QAction. setShortcuts ( shortcuts )
    参数: shortcuts
    PySide.QtGui.QAction. setSoftKeyRole ( softKeyRole )
    参数: softKeyRole PySide.QtGui.QAction.SoftKeyRole

    This property holds the action's softkey role.

    This indicates what type of role this action describes in the softkey framework on platforms where such a framework is supported. Currently this is only supported on the Symbian platform.

    The softkey role can be changed any time.

    PySide.QtGui.QAction. setStatusTip ( statusTip )
    参数: statusTip – unicode

    This property holds the action's status tip.

    状态提示显示在由动作的顶层父级 Widget 提供的所有状态栏上。

    默认情况下,此特性包含空字符串。

    PySide.QtGui.QAction. setText ( text )
    参数: text – unicode

    This property holds the action's descriptive text.

    If the action is added to a menu, the menu option will consist of the icon (if there is one), the text, and the shortcut (if there is one). If the text is not explicitly set in the constructor, or by using PySide.QtGui.QAction.setText() , the action's description icon text will be used as text. There is no default text.

    PySide.QtGui.QAction. setToolTip ( tip )
    参数: tip – unicode

    This property holds the action's tooltip.

    此文本用于工具提示。若工具提示未指定,使用动作文本。

    默认情况下,此特性包含动作的文本。

    PySide.QtGui.QAction. setVisible ( arg__1 )
    参数: arg__1 PySide.QtCore.bool

    This property holds whether the action can be seen (e.g. in menus and toolbars).

    visible is true the action can be seen (e.g. in menus and toolbars) and chosen by the user; if visible is false the action cannot be seen or chosen by the user.

    Actions which are not visible are not grayed out; they do not appear at all.

    By default, this property is true (actions are visible).

    PySide.QtGui.QAction. setWhatsThis ( what )
    参数: what – unicode

    This property holds the action's “What's This?” help text.

    The “What's This?” text is used to provide a brief description of the action. The text may contain rich text. There is no default “What's This?” text.

    另请参阅

    PySide.QtGui.QWhatsThis Q3StyleSheet

    PySide.QtGui.QAction. shortcut ( )
    返回类型: PySide.QtGui.QKeySequence

    This property holds the action's primary shortcut key.

    此特性的有效键码可以找到,在 Qt.Key and Qt.Modifier 。没有默认的快捷键。

    PySide.QtGui.QAction. shortcutContext ( )
    返回类型: PySide.QtCore.Qt.ShortcutContext

    This property holds the context for the action's shortcut.

    可以找到此特性的有效值在 Qt.ShortcutContext 。默认值为 Qt.WindowShortcut .

    PySide.QtGui.QAction. shortcuts ( )
    返回类型:

    返回快捷键列表,采用首要快捷键作为列表的第一元素。

    PySide.QtGui.QAction. showStatusText ( [ widget=None ] )
    参数: widget PySide.QtGui.QWidget
    返回类型: PySide.QtCore.bool

    更新相关状态栏为 widget 指定通过发送 PySide.QtGui.QStatusTipEvent to its parent widget. Returns true if an event was sent; otherwise returns false.

    若指定 null 小部件,则事件被发送给动作的父级。

    PySide.QtGui.QAction. softKeyRole ( )
    返回类型: PySide.QtGui.QAction.SoftKeyRole

    This property holds the action's softkey role.

    This indicates what type of role this action describes in the softkey framework on platforms where such a framework is supported. Currently this is only supported on the Symbian platform.

    The softkey role can be changed any time.

    PySide.QtGui.QAction. statusTip ( )
    返回类型: unicode

    This property holds the action's status tip.

    状态提示显示在由动作的顶层父级 Widget 提供的所有状态栏上。

    默认情况下,此特性包含空字符串。

    PySide.QtGui.QAction. text ( )
    返回类型: unicode

    This property holds the action's descriptive text.

    If the action is added to a menu, the menu option will consist of the icon (if there is one), the text, and the shortcut (if there is one). If the text is not explicitly set in the constructor, or by using PySide.QtGui.QAction.setText() , the action's description icon text will be used as text. There is no default text.

    PySide.QtGui.QAction. toggle ( )

    这是方便函数,为 checked() property. Connect to it to change the checked state to its opposite state.

    PySide.QtGui.QAction. toggled ( arg__1 )
    参数: arg__1 PySide.QtCore.bool
    PySide.QtGui.QAction. toolTip ( )
    返回类型: unicode

    This property holds the action's tooltip.

    此文本用于工具提示。若工具提示未指定,使用动作文本。

    默认情况下,此特性包含动作的文本。

    PySide.QtGui.QAction. trigger ( )

    这是调用 activate(Trigger) 的方便槽。

    PySide.QtGui.QAction. triggered ( [ checked=false ] )
    参数: checked PySide.QtCore.bool
    PySide.QtGui.QAction. whatsThis ( )
    返回类型: unicode

    This property holds the action's “What's This?” help text.

    The “What's This?” text is used to provide a brief description of the action. The text may contain rich text. There is no default “What's This?” text.

    另请参阅

    PySide.QtGui.QWhatsThis Q3StyleSheet