PDA

View Full Version : QLabel links?



gfunk
22nd December 2006, 23:52
Under the docs for QLabel, http://doc.trolltech.com/4.2/qlabel.html, it talks about a new property called openExternalLinks, which
"Specifies whether QLabel (http://doc.trolltech.com/4.2/qlabel.html) should automatically open links using QDesktopServices :: OpenUrl (http://doc.trolltech.com/4.2/qdesktopservices.html#openUrl)() instead of emitting the anchorClicked() signal."

Is this for real? Is it saying that I can set up a QLabel to be clickable, like a web-browser link, and perhaps have the mouse cursor change when it hovers over the link? If so, how do I set the text so that it can hyperlink to a webpage? I tried something like
<a href=\"http://www.yahoo.com\">yahoo.com</a> but it wouldn't show up as a link, nor could I click on it.

wysota
23rd December 2006, 00:33
Have you noticed this?


Note: The textInteractionFlags set on the label need to include either LinksAccessibleByMouse or LinksAccessibleByKeyboard.

gfunk
23rd December 2006, 00:37
Yes, I had set the flags as well. But it still did not work, was not clickable, nor was it underlined. Is it automatically underlined or should that be done manually (<u> or such)?

wysota
23rd December 2006, 00:42
This seems to work fine:

#include <QApplication>
#include <QLabel>

int main(int argc, char **argv){
QApplication app(argc, argv);
QLabel label;
label.setTextInteractionFlags(Qt::LinksAccessibleB yMouse);
label.setOpenExternalLinks(true);
label.setText("<a href=\"http://www.qtcentre.org\">QtCentre</a>");
label.show();
return app.exec();
}

Maybe the html code tags were changed into entities? Did you setup the text using Designer?