attaching user data pointer to images in QTextEdit
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():
Code:
textImage.setName(myImageName);
QVariant v
= qVariantFromValue
((void *) myUserDataPtr
);
textImage.setProperty(myUserDataPropertyId, v);
tc.insertImage(textImage);
To retrieve the data for an image icon in the QTextEdit:
Code:
if (format.isImageFormat())
{
if (format.hasProperty(myUserDataPropertyId))
{
QVariant v
= format.
property(myUserDataPropertyId
);
// ...
}
}
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()?