当我在 QPlainTextEdit 窗口中输入内容,然后输入 CTRL+Z 撤消时,撤消工作正常。但是当我输入 CTRL+Y 来重做撤消时,什么也没有发生。我错过了什么重做不起作用?
这是我的测试代码:
#!/usr/bin/env python3
# Redo (CTRL+Y) does not restore text after Undo (CTRL+Z)
import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QPlainTextEdit
from PySide6.QtCore import QSize
class ExampleWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.b.insertPlainText("example text 1\nexample text 2\nexample text 3")
self.b.resize(440,240)
if __name__ == "__main__":
app = QApplication(sys.argv)
w = QMainWindow()
w.setMinimumSize(QSize(440, 240))
w.setWindowTitle("QPlainTextEdit undo/redo example")
edit = QPlainTextEdit(w)
edit.insertPlainText("example line 1\nexample line 2\nexample line 3")
edit.resize(440,240)
print("undoRedoEnabled: ", edit.isUndoRedoEnabled())
w.show()
sys.exit( app.exec() )
必须使用适合操作系统的正确按键。