PDA

View Full Version : Update characters QTextCharFormat in QTextEdit



Suppaman
26th July 2013, 22:28
Hi

I'm tring to update a caracter under the mouse pointer, like an hiperlink do when the mouse pass over it.

My code is the following:


void MyClass::mouseMoveEvent(QMouseEvent *event)
{
QTextCharFormat Format;
QTextCursor Cursor;

Cursor = cursorForPosition(event->pos());

if(!Cursor.isNull())
{
Format= Cursor.charFormat();

if(Format.isValid())
{
Format.setFontUnderline(true);
Cursor.setCharFormat(Format);
}
}
}

but nothing happen and the character is not updated. Please, note that this is only an example code, the use of setFontUnderline() is just for explain thet also if I update the character under cursor my update doesn't reflect into the text edit widget. Is there an additional function to call for force the repaint of the character after set the new property?

Thank you

ChrisW67
26th July 2013, 23:51
Is your mouseMoveEvent() ever called, i.e. have you turned on setMouseTracking?
Does the cursor returned have a selection to apply a format to?

What is going to unset the underline?

Suppaman
27th July 2013, 10:31
Hi

Thank you for your reply.

Yes, the mouseMoveEvent() is called, he cursor is valid and I can read correctly the properties of QTextCharFormat object (this part is not reported in the example code but it work). This mean the object returned is a valid copy of the property characters under cusor. My problem is after I changed some property as in example it seem I'm not able to update the status of the characters in object. Also if I call setCharFormat for update the status nothing change into the QTextEdit. I suppose I need to make some additional call for "force" widget repaint but, currently, I have no idea how to do...