Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextBlockUserData and Undo stack
Qt 6.12 LTS is out! See what's new in the release blog

QTextBlockUserData and Undo stack

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi all,

    I would like to ask if anyone of you know how to implement undo feature for QTextDocument to store QTextBlockUserData

    On Qt doc page for QTextBlock::setUserData (QTextBlockUserData * data) function is written:

    "The user data object is not stored in the undo history, so it will not be available after undoing the deletion of a text block"

    So how to be able to restore user data for deleted text?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Pt_develop
      wrote on last edited by
      #2

      A bit late for this reply perhaps but this is actually fairly simple to do using the QTextFormat::UserProperty (0x100000) of the associated QTextBlockFormat for the QTextBlock Instead of getting or setting userData functions. The QTextBlockFormat properties are preserved during undo and redo operations. Instead of storing a data pointer you save the data as a QVariant in the format properties.

      Note, you can also do this for any of the formats that are derived from QTextFormat (i.e., QTextBlockFormat, QTextCharFormat, QTextFrameFormat, and QTextListFormat). In my case I have a simple set of indexes that reference entries to a QHash stored in a structure for my format userData and I have no trouble with undo/redo functions. I also store userData in both block and frame formats successfully using a set of helper functions I developed for that purpose but if the userData is simple enough then setting or getting the data directly is relatively straightforward.

      1 Reply Last reply
      1

      • Login

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