[SOLVED]Syntax highlighting


  • Moderators

    Hi,

    Is there a way to tune the syntax highlighter a little better? It often seems kinda random and I'm not sure the rules are the proper ones for c++.

    Some examples:

    QString variable;
    someOtherVariable = variable;
    

    Type name and variable name are bold but it no longer applies below, where type is normal and variable is red and then normal again inside if statement:

    QFile file("stuff");
    if(file.open(QFile::ReadOnly) { /* ... */ } 
    

    And now the variable is violet:

    widget -> setStylesheet("color: red");
    

    And now a bogus keyword is recognized:

    widget . setStylesheet("color: red");
    

    And now the variable and method are blue and string is not recognized anymore:

    widget -> setStylesheet("QWidget { color: red; }");

  • administrators

    It tries to identify the language. And it does that for every snippet.

    I'll take a look how to make it more consistent.


  • administrators

    Looks like the only reliable way is to use the triple backtick with the language:

    ```cpp

    QString variable;
    someOtherVariable = variable;
    QFile file("stuff");
    if(file.open(QFile::ReadOnly) { /* ... */ } 
    widget -> setStylesheet("color: red");
    widget . setStylesheet("color: red");
    widget -> setStylesheet("QWidget { color: red; }");
    
    QString variable;
    
    someOtherVariable = variable;
    
    QFile file("stuff");
    
    if(file.open(QFile::ReadOnly) { /* ... */ } 
    
    widget -> setStylesheet("color: red");
    
    widget . setStylesheet("color: red");
    
    widget -> setStylesheet("QWidget { color: red; }");
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.