I'm trying to create a little syntax highlighter in Qt, and i want to show a tooltip with the description of the error when the user hoover it.
(I'm subclassing QSyntaxHighlighter)
I've tried the QTextCharFormat::setToolTip
function, but it didn't work :/
The text is red-underlined as expected, but no tooltip are shown when I hover over it.
Did i miss something ? Or should i use another method ?
void CodeHighlighter::highlightBlock(const QString &text)
{
_errorFormat.setProperty(QTextFormat::TextUnderlineStyle, QTextCharFormat::SpellCheckUnderline);
_errorFormat.setProperty(QTextFormat::TextUnderlineColor, QColor(Qt::red));
if (!isLineValid(text.toStdString())) {
// The following line does not work !
_errorFormat.setToolTip(QString::fromStdString(getLastError()));
setFormat(0, text.length(), _errorFormat);
}
for (const HighlightingRule &rule : qAsConst(_highlightingRules)) {
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
while (matchIterator.hasNext()) {
QRegularExpressionMatch match = matchIterator.next();
QTextCharFormat format = this->format(match.capturedStart());
format.merge(rule.format);
setFormat(match.capturedStart(), match.capturedLength(), format);
}
}
}