QWebEngineView Open In External Browser

I am in the process of moving my code from QtWebKit to QtWebEngine. In general, the transition was pretty smooth, but I was stuck in one specific problem. I am using QWebEngineView to display the Google Maps page. Some of the placed markers have infowindows that appear "Click here for more information" that opens a link in an external browser.

Using QtWebKit, this was pretty easy through the setLinkDelegation policy. However, here it looks a little more complicated. I tried to follow the example, but for some reason I need to override QWebEnginePage in QWebEngineView. The following is what I have come up with so far. Any idea how I can relate all this?

thanks

#ifndef MYQWEBENGINEVIEW_H
#define MYQWEBENGINEVIEW_H

#include <QWebEngineView>
#include <QDesktopServices>

class MyQWebEnginePage : public QWebEnginePage
{
    Q_OBJECT

public:
    MyQWebEnginePage(QObject* parent = 0) : QWebEnginePage(parent){}

    bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool isMainFrame)
    {
         qDebug() << "acceptNavigationRequest("<<url << "," << type << "," << isMainFrame<<")";

        if (type == QWebEnginePage::NavigationTypeLinkClicked)
        {
            QDesktopServices::openUrl(url);
            return false;
        }
        return true;
    }
};


class MyQWebEngineView : public QWebEngineView
{
    Q_OBJECT
public:
    MyQWebEngineView(QWidget* parent = 0);
    MyQWebEnginePage* page() const;

};

#endif // MYQWEBENGINEVIEW_H
+4
1

. :

QWebEngineView *view = new QWebEngineView();
MyQWebEnginePage *page = new MyQWebEnginePage();
view->setPage(page);
0

Source: https://habr.com/ru/post/1628351/


All Articles