Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] Harmattan Qt Components: How to open links in Label with external browser?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Harmattan Qt Components: How to open links in Label with external browser?

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 4.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sazius
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sazius
      wrote on last edited by
      #2

      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 :)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        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.

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          task_struct
          wrote on last edited by
          #4

          Does "this":http://doc.qt.nokia.com/4.7-snapshot/qml-qt.html#openUrlExternally-method works on MeeGo?

          "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

          • Linu...
          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            [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.

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sazius
              wrote on last edited by
              #6

              Thanks a lot! I implemented both solutions (signal to C++ and Qt.openUrlExternally) and they both work perfectly! Great forum this one :)

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mlong
                wrote on last edited by
                #7

                [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!

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved