Results 1 to 4 of 4

Thread: Refreshing syntax highlighting

  1. #1
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Refreshing syntax highlighting

    I have a QSyntaxHighlighter "installed" on a QTextEdit. The rules for the syntax highlighter can be dynamically altered by the user. Is there any more convenient way to tell QTextEdit/QTextDocument to refresh it's syntax highlighting than just deleting the old syntax highlighter and then creating a new one. I'm currently doing so and it works, but it seems a bit awkward to me...
    J-P Nurmi

  2. #2
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Refreshing syntax highlighting

    (not tested them much, but give them a try).

    Qt Code:
    1. highlight->setDocument( null );
    2. highlight->setDocument( textEditor->document );
    To copy to clipboard, switch view to plain text mode 

    I am missing this one as well...

  3. The following user says thank you to elcuco for this useful post:

    jpn (26th July 2006)

  4. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Refreshing syntax highlighting

    Thanks for the idea, but I couldn't get it to react anyhow. The only way I have found is to create a new instance every time the rules change..
    When you create an instance of your QSyntaxHighlighter subclass, pass it the QTextEdit or QTextDocument that you want the syntax highlighting to be applied to.
    Isn't this a bit inconvenient..?

    Edit: Seems that this functionality has been added to 4.2:
    void QSyntaxHighlighter::rehighlight () [slot]
    Redoes the highlighting of the whole document.
    Last edited by jpn; 26th July 2006 at 16:18. Reason: The functionality has been added to 4.2
    J-P Nurmi

  5. #4
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Refreshing syntax highlighting

    If you look in the announce forums, you will see my library for syntax higlights. I tried doying this, and on my implementation the application crahsed in ... I am not exactly sure...

    I ended up killing the highlighter, and doing another one, as you did.

Similar Threads

  1. A Qt4 editor part with syntax highlighting and stuff?
    By mgoettsche in forum General Discussion
    Replies: 3
    Last Post: 22nd January 2006, 16:32

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.