1

将超链接设置为 aQTextBrowser时,我希望该链接不要加下划线。在以前的 Qt 版本(例如 2、3、4)中,曾经有一种setLinkUnderline(bool)方法可以完成这项工作。如何用 Qt5 做到这一点?

谢谢

4

1 回答 1

2

一种可能的解决方案是使用 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();
}

在此处输入图像描述

于 2018-11-26T20:04:26.310 回答