4

I'm in the process of moving my code from QtWebKit to QtWebEngine. In general, the transition has been fairly smooth, however, I'm stuck on one particular issue. I use a QWebEngineView to display a Google Maps page. Some of the markers placed have have infowindows that pop up "Click Here for More Information" which opens the link in an external browser.

Using QtWebKit, this was fairly easy through the setLinkDelegation policy. However, it seems a little more complex here. I've tried to follow the example but somehow I need to redefine QWebEnginePage within QWebEngineView. Below is what I've come up with so far. Any idea how I can actually connect this all up?

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
goalie39
  • 41
  • 3

1 Answers1

0

You don't need the second part. Try this:

QWebEngineView *view = new QWebEngineView();
MyQWebEnginePage *page = new MyQWebEnginePage();
view->setPage(page);
Jan Rüegg
  • 9,587
  • 8
  • 63
  • 105