Question

I have a "start page" on my application that is just a QWebView widget that downloads a page from my server.

When the user clicks on a link I'd like it to open in their default browser, not in the widget.

Is there a way to do this with QWebView? Or should I take a different approach?

Was it helpful?

Solution

Just call QWebPage::setLinkDelegationPolicy(QWebPage::DelegateAllLinks) then connect the signal QWebView::linkClicked (const QUrl & url) to a slot, and in the slot execute the browser. Finding out what the default browser is, is slightly more complicated and depends on which desktop the user is running. The environment variable BROWSER often contains the default.

Or use QDesktopServices::openUrl [as suggested by gnud in a comment]

OTHER TIPS

Assuming the links are external, you can just call QWebView::setOpenExternalLinks(true) on your QWebView widget. The property is false by default; setting it to true causes external links to open in your default web browser.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top