Skip to main content

Ralsina.Me — Roberto Alsina's website

Editor: a better QTextEdit

Writ­ing an ed­i­tor is rein­vent­ing the wheel. I know that. I tell my­self Mar­ave is a fine wheel, with dis­tinct fea­tures, and I think that is true, but, if you are rein­vent­ing the wheel, there's no need to rein­vent the axle and the spoke, too.

So, I refac­tored the stuff that I think a text ed­i­tor must pro­vide in­to a nice li­brary, so the next time some­one must in­vent a wheel, he can use Mar­ave's neat spokes and axles:

So, in­tro­duc­ing Ed­i­tor, the most-ob­vi­ous­ly named class ev­er! It's a text edit­ing wid­get for PyQt with ex­tra fea­tures, which you can use as a drop-in re­place­ment for a QTextE­d­it or QPlain­TextE­d­it.

Right now, it lives in­side Mar­ave's SVN but it may even move out some­day.

Here are its fea­tures:

  • Syn­­tax high­­­light­ing

    And I don't mean "in the­o­ry", like QTex­tE­d­it and com­­pa­ny do! Ed­i­­tor can high­­­light a bunch of lan­guages, be­­cause it us­es GNU source high­­­light via Loren­­zo Bet­­tini's Source High­­­light Qt.

  • Spell check­­ing

    If you have PyEn­chant in­­stalled and the right dic­­tio­­nar­ies, it will do on­­line spellcheck­­ing.

  • Search and Search+Re­­place wid­gets

    The Ed­i­­tor class can give you nice wid­gets for search or search and re­­place al­ready hooked with the ed­i­­tor wid­get, so you can add them to your ap­p's UI eas­i­­ly.

  • new/open/save/saveas meth­od­s:

    Don't im­­ple­­ment open­ing/sav­ing, etc your­­self! That's al­ways the same code!

Hope­ful­ly this will be help­ful for some­one else :-)

hajs / 2010-02-23 16:46:

Nice. FYI: I worked on a QPlainTextEdit widget, too. Some preview videos are available at
Code will be released soon (after I cleaned up some stuff).

Roberto Alsina / 2010-02-23 16:55:

Whoa, that's seriously impressive widgetry!

D3f0 / 2010-02-23 22:16:

I've been working for a project called Prymatex for a month or so, the main goal is to produce a programmer text editor compatible with TextMate's bundle set, released unnder GNU GPL (TextMate is propietary code, but the syntax, commands, templates, etc. are not). Although it's a GPL editor, it has lots of thing that need to be polished.

Right now we're struggling with cytpes and Oniguruma, but there's a lot to be done regarding to QTextEdit and I belive your code will be very helpful. Are you going to mantain the project and maybe become an alternative to QScinitlla o C++'s QCodeEdit?

Thanks for sharing :)

Yuri Malheiros / 2010-02-24 00:17:

OMG, CodeAide seems awesome!

Anonymouse / 2010-02-24 02:48:

How hard would it be to implement multiple selections with QtTextEdit? ( ala )

Roberto Alsina / 2010-02-25 00:29:

QTextEdit already supports multiple selections, AFAIK, there's just no UI to actually use them. I'll take a look at that link in a moment to see if I understood you corretly (right now, I need to make pizza!)

phone number lookup / 2011-12-03 22:30:

this is really interesting viewpoint on the subject i might add

employment background check / 2011-12-27 23:28:

Man ... Beautiful . Amazing ... I will bookmark your website and use the your RSS feed also

Contents © 2000-2023 Roberto Alsina