View Full Version : qtsourceview

22nd July 2006, 18:30
This is a demo of a syntax highlighter done in C++/Qt.
The code is extraeamly non optimized, but it does work most of the time.
The class is very slow, so please don't use it on large files.

The syntax highlighter definitions are the same ones used by the gtksourceview library
for gtk. The definitions are passed to a class which does the highligting. This means
that the engine is not aware of what he is coloring, and adding new languages is as
trivial as adding new XML to the langs directory.

The code is very rough, and *slow*, but I am planning in fixing it up until it becomes usable.


18th August 2006, 18:29
Version 0.0.2 has been released.

Better documentation, some speed ups, better code, more hightlights (even a *.pro which I did specially for this release). All the demos are made using the designer, and some I even coded with QIde ;-)


22nd August 2006, 06:41
with ref to the previous version
the highlighting of float does not work correctly

a float const 0.00001
will be highlighted as 0. as float
and 00001 as Hexa

2nd September 2006, 13:41

Sorry for the late response. Did it work on v0.0.1? on my box (qt42 rsync, suse 10.0) i see the problem in v0.0.1 and v0.0.2.

BTW, if anyone us using qt4 rsync, here is a patch for those versions. it seems the trolls are deprecating some old functions which I was using.

diff -ru qtsource-1/src/qsvlangdeffactory.cpp qtsource-3/src/qsvlangdeffactory.cpp
--- qtsource-1/src/qsvlangdeffactory.cpp 2006-07-22 19:06:06.000000000 +0300
+++ qtsource-3/src/qsvlangdeffactory.cpp 2006-09-02 15:36:49.000000000 +0300
@@ -61,7 +61,7 @@
// if do we recognize the mime type defined in that
// syntax highligh definition, check if matches this file

- if ( mimeTypes.find(langMimeType) )
+ if ( mimeTypes.contains(langMimeType) )
for ( int j=0; j<mimeTypes[langMimeType].count(); j ++ )

4th September 2006, 05:31
Even in version 0.2 I could find the same problem .
So I rearranged the regex for the Hexa and floats

i.e in the lang files i Put the floats after the hexa. so floats gets painted after hexa.

And the regex fails to detect .001 as float.
And floats can have 10e-2
the negetive is omitted in the regex

In python.lang strings are not detected. something wrong with the regex i believe.

9th September 2006, 12:21

The problems are not with the regex, since all of them were borrowed from GtkSourceView. Since the GTK widget displays the syntaxes correctly, the only conclusion is that the bug is in the QtSourceView source - my code.

The way I am handling the regex in the source is plain stupid. I need to recode that part and using proper contexts. It's on my TODO list, but I am postponding it, and I will handle this re-write in a few weeks.

If you can fix the non working code, a patch will be cool. You know my email.

30th July 2011, 18:50
After more then 5 years since the last release, I am releasing V0.0.3.

The code now shows a widget for editing text, based on QPlainTextEdit, and two syntax hilighters: the one in version 0.0.2, and a new one base on the source of QtCreator, which is based on the Kate.

My focus will be from now on to port the qate syntax highlighter to be more usable as a stand alone, embeddable text editor widget.

Code is available here:

The source contains also the Doxygen generated documentation. Feel free to download and comment.