我有MainWindow类,它具有qscintilla编辑器,我想向编辑器mousePressEvent添加侦听器
class MainWindow(QtWidgets.QMainWindow, gui.Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.editor.mousePressEvent = self.on_editor_click
def on_editor_click(self, QMouseEvent):
// here i want add my code
return QsciScintilla.mousePressEvent(self, QMouseEvent)
如果我覆盖mousePressEvent-编辑器将损坏(鼠标单击将不起作用)。我尝试调用初始mousePressEvent,但无法正常工作,应用程序崩溃了
class ClickQsciScintilla(QsciScintilla):
clicked = QtCore.pyqtSignal()
def mousePressEvent(self, event):
self.clicked.emit()
QsciScintilla.mousePressEvent(self, event)
然后您创建ClickQsciScintilla的实例并连接到该信号:
self.__editor = ClickQsciScintilla() self.__editor.clicked.connect(self.on_editor_click)
您的处理程序:
def on_editor_click(self): print "Editor was clicked!"