Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QMessageBox with link inside, unable to click

I've already set the textFormat to Qt::RichText, but the link is still un-clickable.

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();

Any solutions? It's confirmed not working with Qt 4.7.

like image 617
daisy Avatar asked Oct 21 '25 12:10

daisy


1 Answers

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
like image 87
Anonymous Avatar answered Oct 24 '25 03:10

Anonymous



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!