How can we create hyper link text in QtGui?
-
wrote on 21 Oct 2011, 03:56 last edited by
I want to display some hyperlink text in my window so that user can interact through it.
-
wrote on 21 Oct 2011, 04:05 last edited by
Hi, QLabel has a property called openExternalLinks that you need to set to true, don't know if you need something else, hope it helps you
-
wrote on 21 Oct 2011, 04:18 last edited by
But i think Qlabel dont provide user interaction.
-
wrote on 21 Oct 2011, 04:28 last edited by
when you say user interaction you mean like an edit? where you can write? why don't you write in the edit a copy it to a label with a link?
-
wrote on 21 Oct 2011, 04:55 last edited by
Ok, does Qlabel will respond to click event?
-
wrote on 21 Oct 2011, 06:04 last edited by
Yes, you can use QLabel. You can put rich text (basically, HTML) in it, including links. You will get signals if users hover or click these HTML links. QLabel does not react to other types of user interaction though. You can use those signals to handle the actions internally. If you want a webbrowser to open, set the openExternalLinks property to true as suggested by Iktwo.
-
wrote on 21 Oct 2011, 07:06 last edited by
I have tried this but Does We can't call any slot by using this?
-
wrote on 21 Oct 2011, 07:11 last edited by
Connect your slot to "QLabel::linkActivated":http://doc.qt.nokia.com/stable/qlabel.html#linkActivated
-
wrote on 21 Oct 2011, 07:12 last edited by
I am sorry, I do not understand what you mean by this question.
I am using the method in an application I build, so I am postive it works.
-
wrote on 21 Oct 2011, 07:28 last edited by
I am using
@ QObject::connect (l, SIGNAL(linkActivated(QString)), wi, SLOT(open()));@but the slot is not get called . Here l is label and wi is any slot.
-
wrote on 21 Oct 2011, 08:06 last edited by
The linkActivated() signal is not emitted if you set "openExternalLinks":http://doc.qt.nokia.com/stable/qlabel.html#openExternalLinks-prop to true
-
wrote on 21 Oct 2011, 08:11 last edited by
[quote author="cincirin" date="1319184392"]The linkActivated() signal is not emitted if you set "openExternalLinks":http://doc.qt.nokia.com/stable/qlabel.html#openExternalLinks-prop to true[/quote]
Good point :-)Also: it might be useful to check the return value of the connect statement and/or the output of the application. If the return value is false, the connect failed. The debug output of the application should tell you what the cause of that failure is.
7/12