QTextEdit をサブクラス化しました
class Q_My_TextEdit(QtGui.QTextEdit):
def __init__(self, *args):
QtGui.QTextEdit.__init__(self, *args)
def undo(self):
print("undo")
#my own undo code
私の他のクラスでは:
self.textedit=Q_My_TextEdit()
def keyPressEvent(self,event):
if event.key()==(Qt.Key_Control and Qt.Key_Z):
self.textedit.undo()
QTextEdit にテキストを入力して CTRL-Z を押すと、元に戻されますが、"元に戻す" 関数は呼び出されません。では、それはどのように詳細に機能するのでしょうか?
背景は、2 番目のステップで新しいテキスト (setText()) を設定したいので、元に戻すスタックが削除されます。元に戻す自体を実行するコードを既に実行していますが、「Z」を使用するとキーショートカットが何らかの形で予約されているため、CTRL-Zでトリガーできません。たとえば、自分の undo を で呼び出すとevent.key()==(Qt.Key_Control and Qt.Key_Y)
、機能します。