Taken from Qt Syntax Highlighter Example:
//single line comment rule
singleLineCommentFormat.setForeground(Qt::darkGray);
rule.pattern = QRegExp("//[^\n]*");
rule.format = singleLineCommentFormat;
highlightingRules.append(rule);
//string rule
quotationFormat.setForeground(Qt::darkGreen);
rule.pattern = QRegExp("\".*\"");
rule.pattern.setMinimal(true);
rule.format = quotationFormat;
highlightingRules.append(rule);
The Problem is when you have something like this:
"inside is darkGreen//"outside is darkGray
As you can see, the result is: inside the quotations will be gray including the double / . But the characters outside "" becomes darkGray which is supposed to be in default font color(normally, black). How do i adjust the RegExp for single line comment inorder for it to know that a green "//" is exempted from the darkGray highlighting rule?
I tried to add this for the singe line comment rule:
rule.pattern.setMinimal(true);
Still won't work. I Also tried:
rule.pattern = QRegExp("//[^\n]*\"*");