我正在尝试为我的编辑器实现快捷方式,但到目前为止我还没有取得任何成功。
我想覆盖一些默认的 QScintilla 快捷方式。我已阅读此答案,但我不确定这是否有助于解决我的问题。
我还阅读了Scintilla ( SCI_ASSIGNCMDKEY
) 文档,但我不知道我应该如何以 Python 的方式使用它。
说清楚:
我想覆盖 QScintilla 快捷方式Ctrl+L并使用我的自定义解决方案(将其分配给我的一个功能)。
我想将命令分配给
SCI_LINEDELETE
快捷方式Ctrl+D。
这是我的想法:
from PyQt5.Qsci import QsciScintilla
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class mainWindow(QMainWindow):
def __init__(self, parent = None):
super(mainWindow, self).__init__(parent)
self.initUI()
def initUI(self):
self.center_window = centerWindow(parent=self)
self.setCentralWidget(self.center_window)
class centerWindow(QWidget):
def __init__(self, parent=None):
super(centerWindow, self).__init__(parent)
self.hhEditor_te = QsciScintilla()
vbox = QVBoxLayout(self)
vbox.addWidget(self.hhEditor_te)
self.setLayout(vbox)
# 1)
# assign a key binding to this function
# self.my_shortcut
# 2)
# assign a key binding to the QScintilla command
# SCI_LINEDELETE
def my_shortcut(self):
pass
# my custom shortcut function
if __name__ == '__main__':
app = QApplication.instance()
if app is None:
app = QApplication(sys.argv)
else:
print('QApplication instance already exists: %s' % str(app))
ex = mainWindow()
ex.setGeometry(0,100,1500,600)
ex.show()
sys.exit(app.exec_())