[SOLVED] QWebView - delegating only a subset of links?
-
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! -
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); }
}@