[Interest] Tooltips and Anchors with QSyntaxHighlighter

Shawn Rutledge Shawn.Rutledge at qt.io
Tue Jan 21 14:26:55 CET 2020


> On 21 Jan 2020, at 13:21, Jonathan Purol <contact at folling.de> wrote:
> 
> Hello everyone,
> 
> I should note this is my first time posting to a mailing list, so apologies if I'm messing up something.
> 
> We're currently trying to write an editable text editor which has two modes, edit and view. In edit mode you can make changes using a specific syntax, and in view mode that is rendered with your usual text-editor things.
> The following features ought to be supported:
> 
> * Bold, Italic, Underlined, and strikethrough text
> * Different font sizes
> * Lists
> * Table Of Contents (i.e. hyperlinks that jump to some place in the text)
> * Coloured Text
> * Aligned Text (horizontal alignment suffices)
> * And two special features:
> --> Links written in markdown format [display text](link) should be clickable and emit a signal `linkClicked(QString const& text)` | Note: They will not be opened in the browser, but rather link to something else in the application

Well if you wanted just a markdown editor, it would be easy with Qt 5.14 since we just added that as a feature.  But your special syntax is different?

> --> Hovering those links should open a tooltip which is able to render the HTML4 subset QT provides for all tooltips

I didn’t get around to trying to implement tooltips in my markdown editor yet, but that sounds nice to have.

> I was delighted to see that QTextCharFormat (https://doc.qt.io/qt-5/qtextcharformat.html) already ships with `setTooltip` and `setAnchor`/`setAnchorHref`/`setAnchorNames`, however once I tried to use those, nothing happened.
> I scoured around online and found two bug reports, both either unanswered, or closed. Digging a bit through the source, it seems that those exact two features are not implemented yet:
> https://github.com/qt/qtbase/blob/bef74b6c3a0a9c8649ea8eb333d80015f76863e4/src/gui/text/qtextodfwriter.cpp#L751
> 
> The two bugreports:
> https://bugreports.qt.io/browse/QTBUG-21553
> https://bugreports.qt.io/browse/QTBUG-80524
> 
> 
> My questions now are:
> 1. Is that a really bug, i.e. was it just forgotten? The first bug report exists since 2011, though I'm unsure of how common it is for TODOs to exist that long in QTs code base.
> 2. If not, is there an ETA for those features, or a plan for when they'll be released?
> 3. If the answer to 2. is not "very soon", what approach should I take to implement those features manually. The timeplan for the document editor was around a month - or at most two, and I'm the sole developer on it, so I'm looking for something that's doable in that time frame (I.e. not having to write everything from scratch).

I doubt there was any plan, but if it turns out not to be too hard to fix, maybe there’s still time for 5.15.  I don’t know if I will have time to look at it anytime soon, but maybe.  (The highest priority bugs are the ones from paying customers who have been nagging Qt Support.  As you can see, these bugs have not been prioritized.  Yes we have a lot of such bugs that we haven’t found time to fix, unfortunately.)

I also didn’t get around to trying syntax highlighters for code blocks in markdown, but I’d like to.  It’s a matter of finding spare time for that, since I have plenty of other things to keep me busy.

> I'm aware of `QTextBrowser`, so combining that with `QTextDocument::setHtml` would be one option, though I'm unsure if that would suffice/scale, as we would have to manually reparse user input into HTML, doable, but certainly not as performant.

You could reparse it to markdown if that’s easier.

Or write your own importer.  You can look at qtbase/src/gui/text/qtextmarkdownimporter.cpp and see if you want to write something similar for your syntax.



More information about the Interest mailing list