PDA

View Full Version : Change the indentation with QSyntaxHighlighter



Fred
18th July 2014, 08:34
Hi,

I'm trying to change the indentation of text with the QSyntaxHighlighter, but so far I found no solution. It's easy to change the color or the fontweight but it is also possible to change the indentation? I want to indent comments in my QTextEdit.

Thank you for any suggestions.
Fred


void MyHighlighter::highlightBlock(const QString &text)
{
QTextCharFormat myClassFormat;
myClassFormat.setFontWeight(QFont::Bold);
myClassFormat.setForeground(Qt::darkMagenta);
QString pattern = "\\bMy[A-Za-z]+\\b";

QRegExp expression(pattern);
int index = text.indexOf(expression);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, myClassFormat);
index = text.indexOf(expression, index + length);
}
}

wysota
20th July 2014, 15:45
Do you want to perform indentation by adding extra spaces or tabs or by some other means?