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. [SOLVED] QWebView - delegating only a subset of links?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QWebView - delegating only a subset of links?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.2k 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.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    I have this QWebView that is set to open the machine web browser every time a link is clicked.

    It works fine, but I want only to open the browser depending on the link clicked (only open browser for external website URL, not my local domain)
    I did this slot, but the problem is that with .setUrl(), the QWebview reload the page and makes the page disappear for a few seconds, is there a way to only redirect to the default linkDelegationPolicy when the domain name is mine?

    @
    ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
    connect(ui->webView, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedWebView(QUrl)));

    void DialogInfoWebView::linkClickedWebView(QUrl url) {

    if (!url.toString().contains("maximumtrainer", Qt::CaseInsensitive)) {
        QDesktopServices::openUrl(url);
    }
    else {
        ui->webView->setUrl(url);  //Not good, make the QWebView flash for 1sec, I don't need to reload page, it's just redirecting to an anchor tag (#)
    }
    

    }
    @

    Found the same question here :
    "http://www.qtcentre.org/threads/58258-QWebView-catching-the-linkClicked-for-use-as-a-filter":http://www.qtcentre.org/threads/58258-QWebView-catching-the-linkClicked-for-use-as-a-filter
    no answer yet.. Thanks!


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    1
    • M Offline
      M Offline
      maximus
      wrote on last edited by
      #2

      Fixed.

      Use .load instead of .setUrl

      @void DialogInfoWebView::linkClickedWebView(QUrl url) {

      qDebug() << "LINK CLICKED!";
      
      
      if (!url.toString().contains("maximumtrainer", Qt::CaseInsensitive)) {
          QDesktopServices::openUrl(url);
      }
      else {
          ui->webView->load(url);
      }
      

      }@


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      1

      • Login

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