[Interest] Tooltips and Anchors with QSyntaxHighlighter

Jonathan Purol contact at folling.de
Tue Jan 21 13:21:40 CET 2020


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
--> Hovering those links should open a tooltip which is able to render 
the HTML4 subset QT provides for all tooltips

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'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.


Thanks in Advance!
Jonathan Purol



More information about the Interest mailing list