Add in a default implementation of the event() override

This commit is contained in:
Kovid Goyal 2014-01-18 11:15:17 +05:30
parent 84ae3b8595
commit 081836db66

View File

@ -55,9 +55,7 @@ class LineNumbers(QWidget): # {{{
class PlainTextEdit(QPlainTextEdit): class PlainTextEdit(QPlainTextEdit):
''' A class that overrides some methods from QPlainTextEdit to fix handling ''' A class that overrides some methods from QPlainTextEdit to fix handling
of the nbsp unicode character. In addition to this you also have to of the nbsp unicode character. '''
override the default copy/cut actions triggered by the keyboard shortcuts.
See the event() method of the TextEdit class for example. '''
def __init__(self, parent=None): def __init__(self, parent=None):
QPlainTextEdit.__init__(self, parent) QPlainTextEdit.__init__(self, parent)
@ -97,6 +95,13 @@ class PlainTextEdit(QPlainTextEdit):
md.setText(self.selected_text) md.setText(self.selected_text)
clipboard.setMimeData(md, clipboard.Selection) clipboard.setMimeData(md, clipboard.Selection)
def event(self, ev):
if ev.type() == ev.ShortcutOverride and ev in (QKeySequence.Copy, QKeySequence.Cut):
ev.accept()
(self.copy if ev == QKeySequence.Copy else self.cut)()
return True
return QPlainTextEdit.event(self, ev)
class TextEdit(PlainTextEdit): class TextEdit(PlainTextEdit):
def __init__(self, parent=None): def __init__(self, parent=None):