Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-80524

QTextCharFormat tool tips not shown when using QSyntaxHighlighter

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.12.5
    • Fix Version/s: None
    • Component/s: GUI: Text handling
    • Labels:
      None
    • Platform/s:
      Linux/X11

      Description

      The tooltip set on a QTextCharFormat is not displayed when using the QSyntaxHighlighter setFormat method to format a block of text.

      Changing the constructor in the highlighter.cpp file from the SyntaxHighlighter example to the code below has no effect.

      When hoovering the text highlighted in dark blue, no tooltips are shown, despite the `setToolTip` function call. The foreground and the font weight are applied correctly, but not the tool tip. 

      This bug was already reported for earlier versions of qt (QTBUG-21553) and is still relevant.

       

      I've linked a screeshot of the execution of the code below (sorry for the low-quality, have to take it with my phone the capture the mouse cursor)

       

      You can use the following code to reproduce this bug (adapted from https://doc.qt.io/qt-5/qtwidgets-richtext-syntaxhighlighter-example.html). 

       

      Highlighter::Highlighter(QTextDocument *parent)
          : QSyntaxHighlighter(parent)
      {
          HighlightingRule rule;
      
          keywordFormat.setForeground(Qt::darkBlue);
          keywordFormat.setFontWeight(QFont::Bold);
      
          // THIS NEXT LINE SEEMS TO HAVE NO EFFECT
          keywordFormat.setToolTip("Test tooltip");
      
          QStringList keywordPatterns;
          keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b"
                          << "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b"
                          << "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b"
                          << "\\blong\\b" << "\\bnamespace\\b" << "\\boperator\\b"
                          << "\\bprivate\\b" << "\\bprotected\\b" << "\\bpublic\\b"
                          << "\\bshort\\b" << "\\bsignals\\b" << "\\bsigned\\b"
                          << "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b"
                          << "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b"
                          << "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b"
                          << "\\bvoid\\b" << "\\bvolatile\\b";
          foreach (const QString &pattern, keywordPatterns) {
              rule.pattern = QRegExp(pattern);
              rule.format = keywordFormat;
              highlightingRules.append(rule);
          }
      }
      
      void Highlighter::highlightBlock(const QString &text)
      {
          for (const HighlightingRule &rule : qAsConst(highlightingRules)) {
              QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
              while (matchIterator.hasNext()) {
                  QRegularExpressionMatch match = matchIterator.next();
                  setFormat(match.capturedStart(), match.capturedLength(), rule.format);
              }
          }
      }
      

       

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              srutledg Shawn Rutledge
              Reporter:
              azyrod Francois Michaut
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes