Results 1 to 2 of 2

Thread: Change the indentation with QSyntaxHighlighter

  1. #1
    Join Date
    Apr 2009
    Posts
    26
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Change the indentation with QSyntaxHighlighter

    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

    Qt Code:
    1. void MyHighlighter::highlightBlock(const QString &text)
    2. {
    3. QTextCharFormat myClassFormat;
    4. myClassFormat.setFontWeight(QFont::Bold);
    5. myClassFormat.setForeground(Qt::darkMagenta);
    6. QString pattern = "\\bMy[A-Za-z]+\\b";
    7.  
    8. QRegExp expression(pattern);
    9. int index = text.indexOf(expression);
    10. while (index >= 0) {
    11. int length = expression.matchedLength();
    12. setFormat(index, length, myClassFormat);
    13. index = text.indexOf(expression, index + length);
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Change the indentation with QSyntaxHighlighter

    Do you want to perform indentation by adding extra spaces or tabs or by some other means?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Using QSyntaxHighlighter
    By chris_helloworld in forum Qt Programming
    Replies: 0
    Last Post: 5th October 2010, 11:22
  2. Creator indentation loses context
    By melon in forum Qt Tools
    Replies: 1
    Last Post: 9th August 2010, 12:34
  3. code indentation
    By jajdoo in forum Newbie
    Replies: 0
    Last Post: 17th July 2010, 16:33
  4. xemacs for qt indentation
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 7th March 2010, 05:15
  5. Implementation of right indentation in a text editor
    By sukanyarn in forum Qt Programming
    Replies: 11
    Last Post: 26th September 2006, 13:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.