Hi,

I'd like to create a QTextEdit subclass in which image icons with some associated data can be included within the text.

To add an image icon and associate data, I'm using QTextFormat::setProperty():

Qt Code:
  1. QTextImageFormat textImage;
  2. textImage.setName(myImageName);
  3. QVariant v = qVariantFromValue((void *) myUserDataPtr);
  4. textImage.setProperty(myUserDataPropertyId, v);
  5. QTextCursor tc = textCursor();
  6. tc.insertImage(textImage);
To copy to clipboard, switch view to plain text mode 

To retrieve the data for an image icon in the QTextEdit:

Qt Code:
  1. QTextFormat format = textCursor.charFormat();
  2. if (format.isImageFormat())
  3. {
  4. if (format.hasProperty(myUserDataPropertyId))
  5. {
  6. QVariant v = format.property(myUserDataPropertyId);
  7. // ...
  8. }
  9. }
To copy to clipboard, switch view to plain text mode 

This works as long as the image icons are not displaced. If I select a section of text and icons, and drag-and-drop them to a different position within the QTextEdit, the user property seems to get lost.

Is this the expected behaviour or am I doing something wrong? Should I be using a different approach than QTextFormat::setProperty()?