Important: Please read the Qt Code of Conduct -

Bug in QSyntaxHighlighter?

  • Hello,

    I am using Code from an old version of Qt (4.1 or something like that) and i think there is a bug in the new version (4.8 or 4.7).
    In the old version everything worked well, the full text appeared. But Compiling and running it with newer versions, there vanish some lines, my observation was: the first line, where NO RULE had matched, i.e NO FORMAT had been set in the line, is visible. Following lines with no highlighting are not shown, but still exist in the window (if I vcall "getPlaintext()" the whole text is returend.

    I solved it now by this:
    QTextCharFormat normalF;
    normalF.setForeground(QBrush((new QColor(0,0,0))->toRgb()));

    bool highlighted = false;
    foreach (HighlightingRule rule, highlightingRules) {
    QRegExp [removed]rule.pattern);
    int index = text.indexOf(expression);
    while (index >= 0) {
    int length = expression.matchedLength();
    if(expression.cap().trimmed() !=""){
    setFormat(index, length, rule.format);
    highlighted = true;
    index = text.indexOf(expression, index + length);
    setFormat(0, text.length(), normalF);

    What means I just use a format with black (normal text) for every line which is not highlighted.
    It works, but I would like to know whether thats a bug or a feature...

    best regard,

Log in to reply