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. QTextBlockUserData and Undo stack
Forum Updated to NodeBB v4.3 + New Features

QTextBlockUserData and Undo stack

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 868 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.
  • K Offline
    K Offline
    kaldorz
    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 Extensions
      • Unsolved