Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QWebView, DelegateExternalLinks and anchors
Forum Updated to NodeBB v4.3 + New Features

QWebView, DelegateExternalLinks and anchors

Scheduled Pinned Locked Moved Solved Qt WebKit
3 Posts 2 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.
  • D Offline
    D Offline
    derda17
    wrote on last edited by derda17
    #1

    Hi,

    I'm trying to use QWebView to display on-the-fly generated html reports. Their source is generated as valid html/css and the passed to the qwebview by setHtml( content )

    The generated code contains three types of links:

    1. links to anchors within the generated code
    2. external links, that should be opened in a external browser
    3. links with a special scheme to be handled within the application

    Out-of-the-box, type 1 works perfectly, 2 are opened inside the webview and 3 are ignored.

    To handle 2 and 3 I set

    qwebview->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
    

    and connect the linkClicked() signal to aprocessing slot.
    This resolves type 2, but anchors result now in an error about:blank#<anchorID> Error while opening the location, the location is not supported (wording may actually be slightly different). Any idea, how I can keep working anchors while handling the other types by myself?

    QT version: 4.8.6

    //edit: typo

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Konstantin Tokarev
      wrote on last edited by
      #2

      You should override QWebPage::acceptNavigationRequest and implement your own navigation policy.

      1 Reply Last reply
      1
      • D Offline
        D Offline
        derda17
        wrote on last edited by derda17
        #3

        So if I inherit from QWebPage and override acceptNavigationRequest, it should simply work like

        qwebview->setPage( myNewWebPage );
        qwebview->setHtml( myContent );
        

        shouldn't it?

        //edit: yes it does. Thank you, it worked perfectly fine.

        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