PDA

View Full Version : Hyperlink text in QLabel to open web browser



qt_developer
22nd May 2012, 11:40
Hi all,

I'm developing an about window. In this window I have some urls.

For example, if my label has the text: "http://www.qtcentre.org" I want that when the user click in the label, the web browser opens with the specified url.

What is the best way to perform this?

Regards.

Zlatomir
22nd May 2012, 12:13
You can use openExternalLinks (http://qt-project.org/doc/qt-4.8/qlabel.html#openExternalLinks-prop)

qt_developer
22nd May 2012, 14:32
Hi Zlatomir,

I have set openExternalLinks, LinksAccessibleByMouse and LinksAccessibleByKeyboard to true, but nothing happen when I click over the QLabel.

What's wrong?

Regards.

srazi
22nd May 2012, 15:59
Is it a link? I mean the text should be like this:


QLabel label;
label.openExternalLinks(true);
label.setText("<a href=\"http://www.qtcentre.org\" />QtCentre</a>");

qt_developer
22nd May 2012, 18:51
Hi srazi,

I have used your code but nothing happens when I click over the label. Have you tested the code?

Regards.

Talei
22nd May 2012, 19:18
Did You set text format to Plain text on QLabel? If so change it to Auto / Rich text.

aM101kS
17th July 2017, 17:35
hello world
the right code is :
QLabel label;
label.openExternalLinks(true);
label.setText("<a href=\"http://www.qtcentre.org\">QtCentre</a>");
i tested and it's work

orgads
4th October 2018, 06:47
The really right code is:

QLabel label;
label.setOpenExternalLinks(true);
label.setText("<a href="http://www.qtcentre.org">QtCentre</a>");