QShortcut¶
Synopsis¶
Functions¶
def
autoRepeat
()def
context
()def
id
()def
isEnabled
()def
key
()def
parentWidget
()def
setAutoRepeat
(on)def
setContext
(context)def
setEnabled
(enable)def
setKey
(key)def
setWhatsThis
(text)def
whatsThis
()
Signals¶
def
activated
()def
activatedAmbiguously
()
Detailed Description¶
The
QShortcut
class provides a way of connecting keyboard shortcuts to Qt’s signals and slots 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 theQAction
class.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’sactivated()
signal is emitted. (In the case of ambiguity, theactivatedAmbiguously()
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 withkey()
. A shortcut can be enabled or disabled withsetEnabled()
, and can have “What’s This?” help text set withsetWhatsThis()
.See also
-
class
QShortcut
(arg__1, arg__2, arg__3[, arg__4=Qt.WindowShortcut])¶ QShortcut(parent)
QShortcut(key, parent[, member=None[, ambiguousMember=None[, context=Qt.WindowShortcut]]])
Constructs a
QShortcut
object for theparent
widget. Since no shortcut key sequence is specified, the shortcut will not emit any signals.See also
Constructs a
QShortcut
object for theparent
widget. The shortcut operates on its parent, listening forQShortcutEvent
s that match thekey
sequence. Depending on the ambiguity of the event, the shortcut will call themember
function, or theambiguousMember
function, if the key press was in the shortcut’scontext
.
-
PySide2.QtWidgets.QShortcut.
activated
()¶
-
PySide2.QtWidgets.QShortcut.
activatedAmbiguously
()¶
-
PySide2.QtWidgets.QShortcut.
autoRepeat
()¶ - Return type
bool
See also
-
PySide2.QtWidgets.QShortcut.
context
()¶ - Return type
ShortcutContext
See also
-
PySide2.QtWidgets.QShortcut.
id
()¶ - Return type
int
Returns the shortcut’s ID.
See also
shortcutId()
-
PySide2.QtWidgets.QShortcut.
isEnabled
()¶ - Return type
bool
-
PySide2.QtWidgets.QShortcut.
parentWidget
()¶ - Return type
Returns the shortcut’s parent widget.
-
PySide2.QtWidgets.QShortcut.
setAutoRepeat
(on)¶ - Parameters
on –
bool
See also
-
PySide2.QtWidgets.QShortcut.
setContext
(context)¶ - Parameters
context –
ShortcutContext
See also
-
PySide2.QtWidgets.QShortcut.
setEnabled
(enable)¶ - Parameters
enable –
bool
See also
-
PySide2.QtWidgets.QShortcut.
setWhatsThis
(text)¶ - Parameters
text – unicode
See also
-
PySide2.QtWidgets.QShortcut.
whatsThis
()¶ - Return type
unicode
See also
© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.