内容表

上一话题

QScrollerProperties

下一话题

QSizeGrip

QShortcut

QShortcut class is used to create keyboard shortcuts. 更多

Inheritance diagram of PySide2.QtWidgets.QShortcut

概要

函数

详细描述

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, and 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 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 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 activated() signal is emitted. (In the case of ambiguity, the 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 setKey() and retrieved with key() . A shortcut can be enabled or disabled with setEnabled() , and can have “What’s This?” help text set with setWhatsThis() .

class QShortcut ( arg__1 , arg__2 , arg__3 [ , arg__4=Qt.WindowShortcut ] )

QShortcut(parent)

QShortcut(key, parent[, member=None[, ambiguousMember=None[, shortcutContext=Qt.WindowShortcut]]])

param parent

QWidget

param arg__1

QKeySequence

param arg__2

QWidget

param ambiguousMember

str

param arg__3

PyCallable

param arg__4

ShortcutContext

param member

str

param shortcutContext

ShortcutContext

param key

QKeySequence

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

另请参阅

setKey()

PySide2.QtWidgets.QShortcut. activated ( )
PySide2.QtWidgets.QShortcut. activatedAmbiguously ( )
PySide2.QtWidgets.QShortcut. autoRepeat ( )
返回类型

bool

另请参阅

setAutoRepeat()

PySide2.QtWidgets.QShortcut. context ( )
返回类型

ShortcutContext

另请参阅

setContext()

PySide2.QtWidgets.QShortcut. id ( )
返回类型

int

Returns the shortcut’s ID.

另请参阅

shortcutId()

PySide2.QtWidgets.QShortcut. isEnabled ( )
返回类型

bool

PySide2.QtWidgets.QShortcut. key ( )
返回类型

QKeySequence

另请参阅

setKey()

PySide2.QtWidgets.QShortcut. parentWidget ( )
返回类型

QWidget

Returns the shortcut’s parent widget.

PySide2.QtWidgets.QShortcut. setAutoRepeat ( on )
参数

on bool

另请参阅

autoRepeat()

PySide2.QtWidgets.QShortcut. setContext ( context )
参数

context ShortcutContext

另请参阅

context()

PySide2.QtWidgets.QShortcut. setEnabled ( enable )
参数

enable bool

另请参阅

isEnabled()

PySide2.QtWidgets.QShortcut. setKey ( key )
参数

key QKeySequence

另请参阅

key()

PySide2.QtWidgets.QShortcut. setWhatsThis ( text )
参数

text – unicode

另请参阅

whatsThis()

PySide2.QtWidgets.QShortcut. whatsThis ( )
返回类型

unicode

另请参阅

setWhatsThis()