我需要做什么才能在 Qt QPlainTextEdit 中撤消后重做恢复文本

问题描述 投票:0回答:1

当我在 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() )
python pyside6 undo-redo qplaintextedit
1个回答
0
投票

必须使用适合操作系统的正确按键。

© www.soinside.com 2019 - 2024. All rights reserved.