[Solved] Harmattan Qt Components: How to open links in Label with external browser?
-
I was delighted to see that HTML works nicely in the Label component (of Harmattan Qt Components), and links with A HREF show up underlined and with a clearly separating colour. However, they cannot be clicked (tapped) to open the link in an external browser (such as the Harmattan Web Browser). With Qt/C++ QLabel you can simply set QLabel::setOpenExternalLinks(true) and it works perfectly. Is there some way to make the "clickable-looking" links in Label actually open in an external browser? Or is there some other way of displaying simple text with working links in a Qt Component?
-
OK, I actually found the first step on the way myself. Label is just a fancy Text component. Text has an onLinkActivated signal which can be used in Label as well, e.g.:
@
Label {
text: someTextWithLink
onLinkActivated: console.log(link)
}
@Now I just need to figure out how to open that in a browser :)
-
I created a helper class in C++ which has a slot which wraps "QDesktopServices::openUrl()":http://doc.qt.nokia.com/4.7-snapshot/qdesktopservices.html#openUrl. From there, I used the "Text::onLinkActivated()":http://doc.qt.nokia.com/4.7-snapshot/qml-text.html#onLinkActivated-signal signal to catch the URL clicks, at which point I pass the URL to my helper class, which opens it in the external browser.
As an aside, if there is native access in QML to openUrl() I'd love to know about it.
-
Does "this":http://doc.qt.nokia.com/4.7-snapshot/qml-qt.html#openUrlExternally-method works on MeeGo?
-
[quote author="task_struct" date="1314904495"]Does "this":http://doc.qt.nokia.com/4.7-snapshot/qml-qt.html#openUrlExternally-method works on MeeGo?[/quote]
Ah! Very nice! If that works, that's a much cleaner solution. I'll go clean up my code right now.
-
[quote author="sazius" date="1314905552"]Thanks a lot! I implemented both solutions (signal to C++ and Qt.openUrlExternally) and they both work perfectly! Great forum this one :)[/quote]
Indeed! I love it when the helpers get helped, too :)
Be sure and edit the thread title to add [Solved]. Thanks!