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

    上一话题

    QGraphicsTextItem

    下一话题

    QSessionManager

    QShortcut

    概要

    函数

    详细描述

    PySide.QtGui.QShortcut class is used to create keyboard shortcuts.

    PySide.QtGui.QShortcut class provides a way of connecting keyboard shortcuts to Qt's 信号和槽 mechanism, so that objects can be informed when a shortcut is executed. The shortcut can be set up to contain all the key presses necessary to describe a keyboard shortcut, including the states of modifier keys such as Shift , Ctrl ,和 Alt .

    On certain widgets, using ‘&' in front of a character will automatically create a mnemonic (a shortcut) for that character, e.g. “E&xit” will create the shortcut Alt+X (use ‘&&' to display an actual ampersand). The widget might consume and perform an action on a given shortcut. On X11 the ampersand will not be shown and the character will be underlined. On Windows, shortcuts are normally not displayed until the user presses the Alt key, but this is a setting the user can change. On Mac, shortcuts are disabled by default. Call qt_set_sequence_auto_mnemonic() to enable them. However, because mnemonic shortcuts do not fit in with Aqua's guidelines, Qt will not show the shortcut character underlined.

    For applications that use menus, it may be more convenient to use the convenience functions provided in the PySide.QtGui.QMenu class to assign keyboard shortcuts to menu items as they are created. Alternatively, shortcuts may be associated with other types of actions in the PySide.QtGui.QAction 类。

    The simplest way to create a shortcut for a particular widget is to construct the shortcut with a key sequence. For example:

    shortcut = QShortcut(QKeySequence(self.tr("Ctrl+O", "File|Open")),
                         parent)
    										

    When the user types the key sequence for a given shortcut, the shortcut's PySide.QtGui.QShortcut.activated() signal is emitted. (In the case of ambiguity, the PySide.QtGui.QShortcut.activatedAmbiguously() signal is emitted.) A shortcut is “listened for” by Qt's event loop when the shortcut's parent widget is receiving events.

    A shortcut's key sequence can be set with PySide.QtGui.QShortcut.setKey() and retrieved with PySide.QtGui.QShortcut.key() . A shortcut can be enabled or disabled with PySide.QtGui.QShortcut.setEnabled() , and can have “What's This?” help text set with PySide.QtGui.QShortcut.setWhatsThis() .

    class PySide.QtGui. QShortcut ( arg__1 , arg__2 , arg__3 [ , arg__4=Qt.WindowShortcut ] )
    class PySide.QtGui. QShortcut ( parent )
    class PySide.QtGui. QShortcut ( key , parent [ , member=0 [ , ambiguousMember=0 [ , context=Qt.WindowShortcut ] ] ] )
    参数:

    构造 PySide.QtGui.QShortcut object for the parent widget. Since no shortcut key sequence is specified, the shortcut will not emit any signals.

    PySide.QtGui.QShortcut. activated ( )
    PySide.QtGui.QShortcut. activatedAmbiguously ( )
    PySide.QtGui.QShortcut. autoRepeat ( )
    返回类型: PySide.QtCore.bool

    This property holds whether the shortcut can auto repeat.

    If true, the shortcut will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.

    PySide.QtGui.QShortcut. context ( )
    返回类型: PySide.QtCore.Qt.ShortcutContext

    This property holds the context in which the shortcut is valid.

    A shortcut's context decides in which circumstances a shortcut is allowed to be triggered. The normal context is Qt.WindowShortcut , which allows the shortcut to trigger if the parent (the widget containing the shortcut) is a subwidget of the active top-level window.

    默认情况下,此特性被设为 Qt.WindowShortcut .

    PySide.QtGui.QShortcut. id ( )
    返回类型: PySide.QtCore.int

    Returns the shortcut's ID.

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

    This property holds whether the shortcut is enabled.

    An enabled shortcut emits the PySide.QtGui.QShortcut.activated() or PySide.QtGui.QShortcut.activatedAmbiguously() signal when a PySide.QtGui.QShortcutEvent occurs that matches the shortcut's PySide.QtGui.QShortcut.key() sequence.

    If the application is in WhatsThis mode the shortcut will not emit the signals, but will show the “What's This?” text instead.

    默认情况下,此特性为 true。

    PySide.QtGui.QShortcut. key ( )
    返回类型: PySide.QtGui.QKeySequence

    This property holds the shortcut's key sequence.

    This is a key sequence with an optional combination of Shift, Ctrl, and Alt. The key sequence may be supplied in a number of ways:

    setKey(0)                  # no signal emitted
    setKey(QKeySequence())     # no signal emitted
    setKey(0x3b1)              # Greek letter alpha
    setKey(Qt.Key_D)           # 'd', e.g. to delete
    setKey('q')                # 'q', e.g. to quit
    setKey(Qt.CTRL + Qt.Key_P) # Ctrl+P, e.g. to print document
    setKey("Ctrl+P")           # Ctrl+P, e.g. to print document
    											

    By default, this property contains an empty key sequence.

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

    Returns the shortcut's parent widget.

    PySide.QtGui.QShortcut. setAutoRepeat ( on )
    参数: on PySide.QtCore.bool

    This property holds whether the shortcut can auto repeat.

    If true, the shortcut will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.

    PySide.QtGui.QShortcut. setContext ( context )
    参数: context PySide.QtCore.Qt.ShortcutContext

    This property holds the context in which the shortcut is valid.

    A shortcut's context decides in which circumstances a shortcut is allowed to be triggered. The normal context is Qt.WindowShortcut , which allows the shortcut to trigger if the parent (the widget containing the shortcut) is a subwidget of the active top-level window.

    默认情况下,此特性被设为 Qt.WindowShortcut .

    PySide.QtGui.QShortcut. setEnabled ( enable )
    参数: enable PySide.QtCore.bool

    This property holds whether the shortcut is enabled.

    An enabled shortcut emits the PySide.QtGui.QShortcut.activated() or PySide.QtGui.QShortcut.activatedAmbiguously() signal when a PySide.QtGui.QShortcutEvent occurs that matches the shortcut's PySide.QtGui.QShortcut.key() sequence.

    If the application is in WhatsThis mode the shortcut will not emit the signals, but will show the “What's This?” text instead.

    默认情况下,此特性为 true。

    PySide.QtGui.QShortcut. setKey ( key )
    参数: key PySide.QtGui.QKeySequence

    This property holds the shortcut's key sequence.

    This is a key sequence with an optional combination of Shift, Ctrl, and Alt. The key sequence may be supplied in a number of ways:

    setKey(0)                  # no signal emitted
    setKey(QKeySequence())     # no signal emitted
    setKey(0x3b1)              # Greek letter alpha
    setKey(Qt.Key_D)           # 'd', e.g. to delete
    setKey('q')                # 'q', e.g. to quit
    setKey(Qt.CTRL + Qt.Key_P) # Ctrl+P, e.g. to print document
    setKey("Ctrl+P")           # Ctrl+P, e.g. to print document
    											

    By default, this property contains an empty key sequence.

    PySide.QtGui.QShortcut. setWhatsThis ( text )
    参数: text – unicode

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

    The text will be shown when the application is in “What's This?” mode and the user types the shortcut PySide.QtGui.QShortcut.key() sequence.

    To set “What's This?” help on a menu item (with or without a shortcut key), set the help on the item's action.

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

    PySide.QtGui.QShortcut. whatsThis ( )
    返回类型: unicode

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

    The text will be shown when the application is in “What's This?” mode and the user types the shortcut PySide.QtGui.QShortcut.key() sequence.

    To set “What's This?” help on a menu item (with or without a shortcut key), set the help on the item's action.

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