Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using QUndoCommand with QTextEdit
Forum Updated to NodeBB v4.3 + New Features

Using QUndoCommand with QTextEdit

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chris H
    wrote on last edited by
    #1

    When implementing a QUndoStack-based undo functionality, how do you deal with things like QTextEdit? I have two concerns: first, if I attach a slot to textChanged() that creates a QUndoCommand, should I store just the inserted text and insertion point, or should I store the whole before and after text? Second, when the QUndoCommand is called with undo(), it will call setText() on the widget, which will then fire off a textChanged()... of course, I don't want to add a new undo event in this case: how do you all work around this?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris H
      wrote on last edited by
      #2

      Answering my own questions here: first, by attaching to textEdited() instead of textChanged(), you are able to ignore any changes to the text made using setText(). Second, since a QLineEdit is a relatively short amount of text I simply stored the old text and the new text: this has the benefit of working regardless of whether the change is an insertion or deletion, letting me use the same Command class. It won't scale well, but for this app that's not a concern.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved