Results 1 to 3 of 3

Thread: QTextEdit with syntax highlighter

  1. #1
    Join Date
    May 2006
    Posts
    32
    Thanks
    1
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QTextEdit with syntax highlighter

    Hello people!

    I want to know how a QTextEdit is enabled with syntax highlighting. Can anyone give me the procedure to check 'C' programming syntax in texteditor. I tried with
    Qt Code:
    1. QSyntaxHighlighter * syntaxHighlighter () const
    To copy to clipboard, switch view to plain text mode 

    but finding difficulty in using this option. Please post a reply.
    Regards

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

    Default Re: QTextEdit with syntax highlighter

    You need to subclass QSyntaxHighlighter and override:
    QSyntaxHighlighter::highlightParagraph()
    This function is called when necessary (the given paragraph has changed).

    Just pass the text edit object to QSyntaxHighlighter's constructor. It will then install the syntax highlighter on the text edit.

    QSyntaxHighlighter::QSyntaxHighlighter(QTextEdit* textEdit):
    Constructs the QSyntaxHighlighter and installs it on textEdit.
    It is the caller's responsibility to delete the QSyntaxHighlighter when it is no longer needed.
    J-P Nurmi

  3. #3
    Join Date
    May 2006
    Posts
    32
    Thanks
    1
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit with syntax highlighter

    Hello
    Thank you for the reply.
    I will try this at my end.
    Regards

Similar Threads

  1. Refreshing syntax highlighting
    By jpn in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2006, 20:09
  2. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  3. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  4. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 18:40
  5. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 14:47

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.