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
QShortcutclass provides a way of connecting keyboard shortcuts to Qt鈥檚 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. 鈥淓&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鈥檚 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
QMenuclass to assign keyboard shortcuts to menu items as they are created. Alternatively, shortcuts may be associated with other types of actions in theQActionclass.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 sequencefor a given shortcut, the shortcut鈥檚activated()signal is emitted. (In the case of ambiguity, theactivatedAmbiguously()signal is emitted.) A shortcut is 鈥渓istened for鈥 by Qt鈥檚 event loop when the shortcut鈥檚 parent widget is receiving events.A shortcut鈥檚 key sequence can be set with
setKey()and retrieved withkey(). A shortcut can be enabled or disabled withsetEnabled(), and can have 鈥淲hat鈥檚 This?鈥 help text set withsetWhatsThis().See also
QShortcutEventQKeySequenceQAction
- class PySide2.QtWidgets.QShortcut(arg__1, arg__2, arg__3[, arg__4=Qt.WindowShortcut])露
PySide2.QtWidgets.QShortcut(parent)
PySide2.QtWidgets.QShortcut(key, parent[, member=None[, ambiguousMember=None[, shortcutContext=Qt.WindowShortcut]]])
- param parent:
- param arg__1:
- param arg__2:
- param ambiguousMember:
str
- param arg__3:
PyCallable- param arg__4:
- param member:
str
- param shortcutContext:
- param key:
Constructs a
QShortcutobject for theparentwidget. Since no shortcut key sequence is specified, the shortcut will not emit any signals.See also
- PySide2.QtWidgets.QShortcut.activated()露
- PySide2.QtWidgets.QShortcut.activatedAmbiguously()露
- PySide2.QtWidgets.QShortcut.autoRepeat()露
- Return type:
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.
- PySide2.QtWidgets.QShortcut.context()露
- Return type:
This property holds the context in which the shortcut is valid.
A shortcut鈥檚 context decides in which circumstances a shortcut is allowed to be triggered. The normal context is
WindowShortcut, which allows the shortcut to trigger if the parent (the widget containing the shortcut) is a subwidget of the active top-level window.By default, this property is set to
WindowShortcut.
- PySide2.QtWidgets.QShortcut.id()露
- Return type:
int
Returns the shortcut鈥檚 ID.
See also
shortcutId()
- PySide2.QtWidgets.QShortcut.isEnabled()露
- Return type:
bool
This property holds whether the shortcut is enabled.
An enabled shortcut emits the
activated()oractivatedAmbiguously()signal when aQShortcutEventoccurs that matches the shortcut鈥檚key()sequence.If the application is in
WhatsThismode the shortcut will not emit the signals, but will show the 鈥淲hat鈥檚 This?鈥 text instead.By default, this property is
true.See also
- PySide2.QtWidgets.QShortcut.key()露
- Return type:
This property holds the shortcut鈥檚 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.
- PySide2.QtWidgets.QShortcut.parentWidget()露
- Return type:
Returns the shortcut鈥檚 parent widget.
- PySide2.QtWidgets.QShortcut.setAutoRepeat(on)露
- Parameters:
on 鈥 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.
- PySide2.QtWidgets.QShortcut.setContext(context)露
- Parameters:
context 鈥
ShortcutContext
This property holds the context in which the shortcut is valid.
A shortcut鈥檚 context decides in which circumstances a shortcut is allowed to be triggered. The normal context is
WindowShortcut, which allows the shortcut to trigger if the parent (the widget containing the shortcut) is a subwidget of the active top-level window.By default, this property is set to
WindowShortcut.
- PySide2.QtWidgets.QShortcut.setEnabled(enable)露
- Parameters:
enable 鈥 bool
This property holds whether the shortcut is enabled.
An enabled shortcut emits the
activated()oractivatedAmbiguously()signal when aQShortcutEventoccurs that matches the shortcut鈥檚key()sequence.If the application is in
WhatsThismode the shortcut will not emit the signals, but will show the 鈥淲hat鈥檚 This?鈥 text instead.By default, this property is
true.See also
- PySide2.QtWidgets.QShortcut.setKey(key)露
- Parameters:
This property holds the shortcut鈥檚 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.
- PySide2.QtWidgets.QShortcut.setWhatsThis(text)露
- Parameters:
text 鈥 str
This property holds the shortcut鈥檚 鈥淲hat鈥檚 This?鈥 help text.
The text will be shown when the application is in 鈥淲hat鈥檚 This?鈥 mode and the user types the shortcut
key()sequence.To set 鈥淲hat鈥檚 This?鈥 help on a menu item (with or without a shortcut key), set the help on the item鈥檚 action.
By default, this property contains an empty string.
See also
inWhatsThisMode()setWhatsThis()
- PySide2.QtWidgets.QShortcut.whatsThis()露
- Return type:
str
This property holds the shortcut鈥檚 鈥淲hat鈥檚 This?鈥 help text.
The text will be shown when the application is in 鈥淲hat鈥檚 This?鈥 mode and the user types the shortcut
key()sequence.To set 鈥淲hat鈥檚 This?鈥 help on a menu item (with or without a shortcut key), set the help on the item鈥檚 action.
By default, this property contains an empty string.
See also
inWhatsThisMode()setWhatsThis()
漏 2022 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.