PDA

View Full Version : Highlighting the keywords in a text edit



divya balachandran
2nd September 2008, 11:21
HI

Iam a beginner in QT-C++ programming..

Here i post this to know how to highlight the keywords in a texteditor..

->I want to highlight the keywords when i open a existing file

-> wnt to highlight the keywords while typing it itself

arbi
2nd September 2008, 11:44
i think you should use QSyntaxHighlighter.

patrik08
2nd September 2008, 14:12
HI

Iam a beginner in QT-C++ programming..

Here i post this to know how to highlight the keywords in a texteditor..

->I want to highlight the keywords when i open a existing file

-> wnt to highlight the keywords while typing it itself

search QScintilla on google or read code from http://www.qt-apps.org/content/show.php/JuffEd?content=59940 latest svn source ...

To draw all QTextLine an his corresponding qrect area is not easy and and Highlightsyntax is already finisch and stable by QScintilla ...

fullmetalcoder
6th September 2008, 15:25
Several solutions exist, each with advantages and drawbacks :


QSyntaxHighlihter (http://doc.trolltech.com/latest/qsyntaxhighlihter.html) : works directly with QTextEdit (http://doc.trolltech.com/latest/qtextedit.html) but requires that you write the highlighting code yourself
QScintilla (http://www.riverbankcomputing.co.uk/static/Docs/QScintilla2/index.html) : replaces QTextEdit/QTextDocument/... with its own classes. Provides highligting for various programming languages but will require a bit of coding if you want highlighting for anything else than the supported languages. Crappy API. No rich text (images, frames, ...)
QCodeEdit (http://qcodeedit.edyuk.org) : replaces QTextEdit and co. Much better API than QScintilla (at least a lot more Qt-like). Syntax highlighting can be done either programmatically or by writing a small XML file defining keywords and, if needed, contexts (i.e comments). No rich text.

hope this helps.