1

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

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Eurydice
  • 8,001
  • 4
  • 24
  • 37

1 Answers1

2

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

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Oh gosh, I tried unsuccessfully with `w.setStyleSheet` instead of `w.document()->setDefaultStyleSheet`. Thanks a lot. – Eurydice Nov 26 '18 at 20:11
  • @Eurydice One thing is Qt StyleSheet that applies to Qt Widgets and another is the css that uses QTextDocument. :-) – eyllanesc Nov 26 '18 at 20:17