PDA

View Full Version : search cursor position of QTextObjects in selection in QTextPlainEdit



binkmers
5th August 2014, 12:37
Hello,

I have a subclass of QPlainTextEdit with createMimeDataFromSelection function overriden.
Text contains plain text and my QTextObjects.
In createMimeDataFromSelection I want to get all TextObjects inside selection. The only working way
I've managed to get by checking every QTextCursor position of the selection:



int endpos = cursor.position();
for (int i = cursor.anchor(); i <= endpos; ++i)
{
cursor.setPosition(i);
qDebug() << cursor.position();
int type = cursor.charFormat().objectType();
if (type == MainDialog::MyTextFormat)
{
qDebug() << "My format";
}
}

This looks cumbersome to me.
I tested cursor.movePosition function with various argument values but it always skipped my TextObject positions
to the end of the selection.
Ideally I want to skip all the plaintext till next TextObject position in the selection.

So, am I missing the proper way?
Thanks