[Interest] QTextCharFormat setAnchor and setAnchorHref inside QSyntaxHighlighter

Mathieu MARACHE mathieu.marache at gmail.com
Fri Jul 18 17:13:17 CEST 2014


Hi !

I'm trying to use a QSyntaxHighlighter just like the sample in the 4.8.6
sources (examples/richtext/syntaxhighlighter) but with a twist : I'd like
to insert anchors and refs. After struggling a couple of hours I couldn't
find any way to make my QTextBrowser to emit any anchorClicked signals...

I modified the example to use a QTextBrowser (set to open both links and
external links) instead of a QTextEdit and added anchors to the
classFormat's QTextCharFormat

     classFormat.setFontWeight(QFont::Bold);
     classFormat.setForeground(Qt::darkMagenta);
+    classFormat.setAnchor(true);
+    classFormat.setAnchorHref("http://www.google.fr");
     rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
     rule.format = classFormat;
     highlightingRules.append(rule);

I was expecting that would be sufficient to have an hypertext link but it's
not the case.

Anyone got any hints on what I'm doing wrong here ?

I attached the modified version of the examples for reference.
--
nǝıɥʇɐƜ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140718/fa304236/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: syntaxhighlighter.zip
Type: application/zip
Size: 8511 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140718/fa304236/attachment.zip>


More information about the Interest mailing list