我正在嘗試使用 PyQt5 和 Python 3.7 在 GUI 應(yīng)用程序中創(chuàng)建撤消和重做按鈕。當(dāng)單擊撤消和重做按鈕時,應(yīng)分別執(zhí)行按鍵序列“Ctrl+Z”和“Ctrl+Y”。我已經(jīng)粗略地瀏覽了 QShortCut 和 QKeySequence 的文檔,但它們似乎是為檢測按鍵序列而不是觸發(fā)它們而設(shè)計的。那么如何實現(xiàn)這些按鈕呢?根據(jù) eyllanesc 的評論,我添加此內(nèi)容是為了更好地解釋我想要實現(xiàn)的目標(biāo)。self.undoButton = self.findChild(QtWidgets.QPushButton, 'undoButton')self.undoButton.clicked.connect(self.undoButtonPressed)self.anyPlainTextEdit = self.findChild(QtWidgets.QPlainTextEdit, 'anyPlainTextEdit')# Function to Execute Key Sequencedef undoButtonPressed(self): # Execute Ctrl+Z Key Sequence我想知道這是否可能。如果不是,我是否應(yīng)該在單獨的變量中維護(hù) PlainTextArea 的先前值和當(dāng)前值,并相應(yīng)地設(shè)置 PlainTextArea 的值?
1 回答

侃侃爾雅
TA貢獻(xiàn)1801條經(jīng)驗 獲得超16個贊
您不必啟動快捷方式來啟用重做或撤消,只需調(diào)用插槽redo()
并undo()
在按下按鈕時:
self.undoButton.clicked.connect(self.anyPlainTextEdit.undo) self.redoButton.clicked.connect(self.anyPlainTextEdit.redo)
添加回答
舉報
0/150
提交
取消