QKeySequenceEdit快捷键编辑器
setKeySequence(QKeySequence keySequence) # 通过键位序列设置默认录制的快捷键
keySequence() -> QKeySequence # 获取录制快捷键返回的键位序列
# QKeySequenceEdit 录制用户按下的快捷键,生成一个键位序列对象
clear() # 清除QKeySequenceEdit中的键位序列对象
editingFinished() # 结束编辑时发射
keySequenceChanged(QKeySequence keySequence) # 键位序列改变时发射
# keySequenceChanged信号会向外发射QKeySequence键位序列对象
枚举值 | 对应快捷键 |
---|---|
HelpContents | F1 |
WhatsThis | Shift+F1 |
Open | Ctrl+O |
Close | Ctrl+F4, Ctrl+W |
Save | Ctrl+S |
Quit | Ctrl+Q |
SaveAs | Ctrl+Shift+S |
New | Ctrl+N |
Delete | Del |
Cut | Ctrl+X, Shift+Del |
Copy | Ctrl+C, Ctrl+Ins |
Paste | Ctrl+V, Shift+Ins |
Preferences | Ctrl+, |
Undo | Ctrl+Z, Alt+Backspace |
Redo | Ctrl+Y, Shift+Ctrl+Z, Alt+Shift+Backspace |
Back | Alt+Left, Backspace |
Forward | Alt+Right, Shift+Backspace |
Refresh | F5 |
ZoomIn | Ctrl+Plus |
ZoomOut | Ctrl+Minus |
FullScreen | F11, Alt+Enter |
Ctrl+P | |
AddTab | Ctrl+T |
NextChild | Ctrl+Tab, Forward, Ctrl+F6 |
PreviousChild | Ctrl+Shift+Tab, Back, Ctrl+Shift+F6 |
Find | Ctrl+F |
FindNext | F3, Ctrl+G |
FindPrevious | Shift+F3, Ctrl+Shift+G |
Replace | Ctrl+H |
SelectAll | Ctrl+A |
Deselect | Ctrl+Shift+A |
Bold | Ctrl+B |
Italic | Ctrl+I |
Underline | Ctrl+U |
MoveToNextChar | Right |
MoveToPreviousChar | Left |
MoveToNextWord | Ctrl+Right |
MoveToPreviousWord | Ctrl+Left |
MoveToNextLine | Down |
MoveToPreviousLine | Up |
MoveToNextPage | PgDown |
MoveToPreviousPage | PgUp |
MoveToStartOfLine | Home |
MoveToEndOfLine | End |
MoveToStartOfDocument | Ctrl+Home |
MoveToEndOfDocument | Ctrl+End |
SelectNextChar | Shift+Right |
SelectPreviousChar | Shift+Left |
SelectNextWord | Ctrl+Shift+Right |
SelectPreviousWord | Ctrl+Shift+Left |
SelectNextLine | Shift+Down |
SelectPreviousLine | Shift+Up |
SelectNextPage | Shift+PgDown |
SelectPreviousPage | Shift+PgUp |
SelectStartOfLine | Shift+Home |
SelectEndOfLine | Shift+End |
SelectStartOfDocument | Ctrl+Shift+Home |
SelectEndOfDocument | Ctrl+Shift+End |
DeleteStartOfWord | Ctrl+Backspace |
DeleteEndOfWord | Ctrl+Del |
InsertParagraphSeparator | Enter |
InsertLineSeparator | Shift+Enter |
Cancel | Escape |
QKeySequence(key_str) # 通过自定义按键序列中字符串方式创建键位序列对象
QKeySequence(QKeySequence.StandardKey key) # 通过标准键位序列枚举值创建键位序列对象
QKeySequence(int k1, int k2 = 0, int k3 = 0, int k4 = 0) # 通过自定义按键序列中的枚举值方式创建键位序列对象
静态方法:fromString(key_str)
toString() -> str # 将键位序列对象转换为可读字符串
count() # 获取键位序列对象中快捷键组数
from PyQt5.Qt import *
import sys
class Windows(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('QKeySequenceEdit-创建使用')
self.resize(500, 500)
self.widget_list()
def widget_list(self):
self.add_widget()
def add_widget(self):
# kse = QKeySequenceEdit(self) # 创建快捷键编辑器对象,并设置父对象
# ks = QKeySequence('Ctrl + C') # 通过自定义按键序列中字符串方式创建按键序列对象
# ks = QKeySequence(QKeySequence.Copy) # 通过标准按键序列枚举值创建按键序列对象
ks = QKeySequence(Qt.CTRL+Qt.Key_S, Qt.ALT + Qt.Key_A) # 通过自定义按键序列中枚举值方式创建按键序列对象
kse = QKeySequenceEdit(ks, self) # 创建快捷键编辑对象的同时设置默认按键序列对象和父对象
kse.move(10, 10)
# 可用信号
# kse.editingFinished.connect(lambda :print('编辑结束了....')) # 编辑结束时发射该信号
kse.keySequenceChanged.connect(lambda key_val :print('按键发生了改变...',key_val))
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Windows()
window.show()
sys.exit(app.exec_())