Grouping user edits in QPlainTextEdit widget
john at sturtz.org
john at sturtz.org
Tue Jun 2 04:33:27 BST 2026
Hi again all.
I have a QPlainTextEdit widget. I place the cursor in the middle of a line, type a few characters and then hit [Enter]. Now if I want to undo that edit, it takes two .undo() calls -- the first removes the newline, the second the typed text.
I'd like to consider the entire edit one group, which a single .undo() undoes.
My ostensible solution was to call .beginEditBlock() prior to the edit, then .endEditBlock() after the edit. And that does in fact work -- a single .undo() call then undoes the entire edit. Unfortunately, after the .beginEditBlock() call, while the edit is occurring, the widget doesn't update.
------
Sample code attached. To demonstrate:
1. Place cursor somewhere in the middle of the line. Type a few characters and hit [Enter].
Type [ctrl+U] to manually call .undo(). First time removes the newline, second time removes the typed characters.
2. Place cursor somewhere (else) on the line.
Type [alt+B] to call .beginEditBlock().
Type a few characters and hit [Enter]. The characters overtype, and the widget doesn't update.
Type [alt+E] to call .endEditBlock(). Now the widget updates.
A single [ctrl+U] undoes the entire edit.
------
Are .beginEditBlock()/.endEditBlock() only really intended to be used for programmatic editing of the text and not user interaction?
Thanks!
/John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20260601/7f584f43/attachment.htm>
More information about the PyQt
mailing list