2

I have a QPlainTextEdit, and I need to get a notification whenever it has selected text which is about to be removed (the reason being I want to backup it).

So I need to be notified when the text is about to be changed, but not changed yet (so no textChanged() signal as it is sent after the change). I could then check if there is a selection and back it up. Unfortunately, there isn't a textChanging(), only a textChanged() signal.

What should I hook in this case?

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • 1
    Look at `QTextDocument` for ideas. I didn't notice an obvious solution, but if the text isn't too large, you could simply take a clone of the document when ever it is changed, and then use [`contentsChange` signal](http://doc.qt.io/qt-5/qtextdocument.html#contentsChange) to discover what code deleted and where, and fetch it from the "backup". Or you could maybe just `undo()` the change, copy the removed text, and `redo()`. I'd write an answer, but I don't know if this will actually work, so just a comment... – hyde Jan 03 '19 at 20:29
  • Thank you, I'll look into it but probably tomorrow as it's getting late in my timezone. – sashoalm Jan 03 '19 at 20:50

0 Answers0