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

QTextCharFormat tool tips not shown when using QSyntaxHighlighter

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P3: Somewhat important
    • None
    • 4.6.3, 4.7.2
    • GUI: Text handling
    • None
    • Windows 7 SP1
      Microsoft Visual Studio 2008

    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.

      Maybe it is not supposed to work, but in that case a hint in the documentation would be nice.

      highlighter.cpp
      //! [0]
      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);
      //! [0] //! [1]
          }
      //! [1]
      
      //! [2]
          classFormat.setFontWeight(QFont::Bold);
          classFormat.setForeground(Qt::darkMagenta);
          rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
          rule.format = classFormat;
          highlightingRules.append(rule);
      //! [2]
      
      //! [3]
          singleLineCommentFormat.setForeground(Qt::red);
          rule.pattern = QRegExp("//[^\n]*");
          rule.format = singleLineCommentFormat;
          highlightingRules.append(rule);
      
          multiLineCommentFormat.setForeground(Qt::red);
      //! [3]
      
      //! [4]
          quotationFormat.setForeground(Qt::darkGreen);
          rule.pattern = QRegExp("\".*\"");
          rule.format = quotationFormat;
          highlightingRules.append(rule);
      //! [4]
      
      //! [5]
          functionFormat.setFontItalic(true);
          functionFormat.setForeground(Qt::blue);
          rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
          rule.format = functionFormat;
          highlightingRules.append(rule);
      //! [5]
      
      //! [6]
          commentStartExpression = QRegExp("/\\*");
          commentEndExpression = QRegExp("\\*/");
      }
      
      

      Debugging showed that QTextFormat::setProperty is called correctly, but QTextFormat::stringProperty returns an empty string, because prop.userType() is not QVariant::String. Also, the d-Pointer is different from the one in setProperty.

      Attachments

        Issue Links

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

          Activity

            People

              Unassigned Unassigned
              abraxas Arne Bergmann
              Votes:
              4 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes