0

When a textEdited() signal is emitted, it can be either because the user has typed/pasted/deleted/replaced some text, or it can be an Undo operation (user has pressed Ctrl+Z, or clicked Undo from the context menu).

I need to distinguish between those somehow. Is there a way to be notified when an Undo operation is performed - subscribe to signal, catch an event perhaps? I couldn't find anything in the QLineEdit documentation myself, but I might have missed it.

Or is there a way to simply check if an Undo has been performed - perhaps a flag, or is there a way to check what the size of the Undo stack is? That way I could compare it its previous size, and if it has decreased, then I would know it's an Undo.

If you want to know why I need this, I'm trying to implement Editable multi-color QLineEdit, and I need this in order to restore the previous colors in the event of an Undo operation.

Community
  • 1
  • 1
sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • Why not to use QTextEdit? I think that "undo" is same legal action, as text editing. – Dmitry Sazonov Jun 06 '14 at 09:12
  • Because I need a QLineEdit for my purposes. If I needed a multi-line widget, I would have used a QTextEdit. What do you mean by "same legal action", though? – sashoalm Jun 06 '14 at 09:19
  • legal == there is no difference for QLineEdit betweed ways of text editing: user unput, programmatically, undo/redo, etc. – Dmitry Sazonov Jun 06 '14 at 10:17

1 Answers1

0

QLineEdit is designed for plain text editing. It is not designed to support advanced formatting. You should use QTextEdit instead. There are a lot of samples in the internet, how to do that.

If you want to practice in creating of custom text editors, then you should implement necessary interface (methods, signals) by yourself.

Dmitry Sazonov
  • 8,801
  • 1
  • 35
  • 61
  • Thanks, but I really can't use a QTextEdit. They are different, it's like telling me to use a QComboBox instead of a QLineEdit. Also, you don't attempt to answer my question. I don't ask if I should use a QTextEdit instead of a QLineEdit, I ask if I can check whether an Undo operation has occurred in a QLineEdit. That's my question. – sashoalm Jun 06 '14 at 13:46
  • My correct answer is - you can't. And I hope, you can explain, why you can't use QTextEdit? It's like saying "I want a checkbox, but not a QCheckBox" – Dmitry Sazonov Jun 06 '14 at 13:59
  • By the way, I tested the single-line QTextEdit example you linked to, but it won't work for me - I need inserted text to be always black, while when using rich text format, it is the color of the surrounding text. Also, in a QLineEdit when you reach the left or right end of the widget with the cursor, it moves it half a widget length, so the cursor comes to be the center. In your example, it moves just once, which is not the same behavior. And who knows if it's possible or not, I've already implemented a QLineEdit that supports colors. It just doesn't play well with Undo. – sashoalm Jun 06 '14 at 14:04