Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextBrowser::anchorClicked not emitted for external links?

QTextBrowser::anchorClicked not emitted for external links?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 880 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.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by
    #1

    It looks like it is only emitted for internal links. I have a slot attached to this signal which is called when an internal link is clicked, but it is not called for external links.

    What I would like to do is to ask/prompt the user on a per-link basis if they want to open an external link. I have seen the forum topic "QTextBrowser::anchorClicked not emitted" from about two years ago, but I am using the standard QTextBrowser and not a subclass of it.

    I know that I can set the openExternalLinks property, but how to do it on a per-link basis if the signal is never emitted?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Set openExternalLinks to false, connect to anchorClicked and then do your decision if you want to open the link or not there.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        Set openExternalLinks to false, connect to anchorClicked and then do your decision if you want to open the link or not there.

        R Offline
        R Offline
        Robert Hairgrove
        wrote on last edited by Robert Hairgrove
        #3

        @Christian-Ehrlicher Thanks, I've gotten that far by now, too. The problems I still have are these:

        1. I can set the openExternalLinks property to true in the slot, but the user must click on the link once again in order to open the link;
        2. Once I have set openExternalLinks property to true, the slot is never called again except for internal links.

        I can live with this if necessary. I show the URL to each external link in the status bar, so maybe this is enough. But is there a better way? IOW, how do I open the external link and leave openExternalLinks set to false?

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          This is not what I wrote.
          You should set openExternalLinks to false, connect to anchorClicked and when you then decide to open the link then simply call setSource with the url you want.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          R 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            This is not what I wrote.
            You should set openExternalLinks to false, connect to anchorClicked and when you then decide to open the link then simply call setSource with the url you want.

            R Offline
            R Offline
            Robert Hairgrove
            wrote on last edited by
            #5

            @Christian-Ehrlicher : When I call setSource with the external URL after asking the user whether to open the link or not, and the user cklicks "OK", the QTextBrowser widget shows a blank page and does not open the internet browser.

            Or am I missing something else? For example, is there a way of opening the external link without calling setSource?

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Robert Hairgrove
              wrote on last edited by Robert Hairgrove
              #6

              OK, problem is solved ... after looking at the sources, I needed to call QDesktopServices::openUrl() (which is what QTextBrowser does) and additionally setSource() with the existing source URL of the text browser in order to make it work (i.e. in order to avoid the blank page in QTextBrowser).

              Thanks to all!

              1 Reply Last reply
              3
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                The please mark the topic as solved :)

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                R 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  The please mark the topic as solved :)

                  R Offline
                  R Offline
                  Robert Hairgrove
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher Done (already)!

                  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