3

我已经将 设置textFormatQt::RichText,但链接仍然不可点击。

QMessageBox msgBox(this);
msgBox.setWindowTitle(QApplication::applicationName()
                      + " $VER " + QApplication::applicationVersion());
msgBox.setTextFormat(Qt::RichText);   //this is what makes the links clickable
msgBox.setText("<a href=\"google.com\">Google</a>");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();

有什么解决办法吗?已确认不适用于 Qt 4.7。

4

1 回答 1

4

It is working under mine Qt 4.7.4, albeit I had to modify your HTML. Minimal example:

#include <QApplication>
#include <QMessageBox>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QMessageBox msgBox;
    msgBox.setTextFormat(Qt::RichText);   //this is what makes the links clickable
    msgBox.setText("<a href='http://google.com/'>Google</a>");
    msgBox.setStandardButtons(QMessageBox::Ok);
    msgBox.exec();
    return app.exec();
}

If I use this one, the browser tab is getting opened, and following message ends up in my console:

Created new window in existing browser session.

If I use your msgBox.setText I get error:

gvfs-open: file:///tmp/b/google.com: error opening location: Error stating file '/tmp/b/google.com': No such file or directory
于 2012-04-05T12:41:52.863 回答