What do I need to do to make redo restore text after undo in Qt QPlainTextEdit

48 views Asked by At

When I type into a QPlainTextEdit window and then type CTRL+Z to undo the undo works fine. But then when I type CTRL+Y to redo the undo nothing happens. What am I missing that redo does not work?

Here is my test code:

#!/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() )
1

There are 1 answers

0
Bruce On

The correct keystroke for the OS must be used.