Not underlining hyperlink in QTextBrowser

308 Views Asked by At

When setting an hyperlink to a QTextBrowser, I would like that link not to be underlined. In previous versions of Qt (e.g. 2,3,4), there used to be a setLinkUnderline(bool) method which probably did the job. How to do this with Qt5 ?

thanks

1

There are 1 best solutions below

2
On BEST ANSWER

A possible solution is to eliminate the underline using css:

#include <QApplication>
#include <QTextBrowser>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTextBrowser w;
    w.document()->setDefaultStyleSheet("a{ text-decoration: none; }");
    w.append("<a href=\"https://stackoverflow.com/\">Stack Overflow</a>");
    w.show();
    return a.exec();
}

enter image description here