PDA

View Full Version : QTextEdit with custom object inside. How to retrieve them by cursor position?



Suppaman
19th July 2013, 08:05
Hi all

I have a QTextEdit control filled by a custom object instead of standard letters. For insert object I got the example from qt package as follow:


QTextCursor cursor = textEdit->textCursor();
cursor.insertText(QString(QChar::ObjectReplacement Character), MyCharFormat);
textEdit->setTextCursor(cursor);

It word very well. Now I want to activate the mouse cursor tracking for the editor and get the object currently under the cursor. I use a code similat to the following:


int textCursorPosition = document()->documentLayout()->hitTest( event->pos(), Qt::FuzzyHit );

This function will return the cursot position of the object under the mouse pos but, once got this coordinate, how to get the pointer to my custom object structure? In case of standard letter I could use the following code:


QChar character( textDocument->characterAt( textCursorPosition ) );

But what about custom object?

Thank you