dvirtz
12th October 2011, 07:48
Hi.
I have a QTextEdit subclass coupled with a QSyntaxHighlighter. After the syntax is highlighted I try to get the char format and the text under a certain position. The text returns correctly, but the format I get seems to be the the default format and not the format I set on the highlighter at this position.
This is the code:
QString LineTextEdit::getTextAndPropertyAtPosition( const QPoint & pos, QTextCharFormat *format)
{
QTextCursor cursor = cursorForPosition(pos);
cursor.select(QTextCursor::WordUnderCursor);
if (format != NULL)
{
*format = cursor.charFormat();
}
QString rc = cursor.selectedText();
cursor.clearSelection();
return rc;
}
I have a QTextEdit subclass coupled with a QSyntaxHighlighter. After the syntax is highlighted I try to get the char format and the text under a certain position. The text returns correctly, but the format I get seems to be the the default format and not the format I set on the highlighter at this position.
This is the code:
QString LineTextEdit::getTextAndPropertyAtPosition( const QPoint & pos, QTextCharFormat *format)
{
QTextCursor cursor = cursorForPosition(pos);
cursor.select(QTextCursor::WordUnderCursor);
if (format != NULL)
{
*format = cursor.charFormat();
}
QString rc = cursor.selectedText();
cursor.clearSelection();
return rc;
}