Qt World Summit: Submit your Presentation

C++/QWebEngineView: How to obtain the link clicked by "right-click" + "open in new tab"?

  • In QWebEngineView: How to obtain the link clicked by "right-click" + "open in new tab"?

    Actually I've succeded to catch the action of "open in new tab" (after right-click) by doing this:

    QAction* openInNewTab = view->pageAction(QWebEnginePage::OpenLinkInNewTab);
    connect(openInNewTab, SIGNAL(triggered()), this, SLOT(on_actionNewTab_triggered()));

    But in my slot on_actionNewTab_triggered(), I have no possibility to know which url to load. I tried to know if there is something in the data of QAction*

    QVariant va;
    QAction* action = (QAction*)  sender();
    va = action->data();

    but the data (va) contains no url !

  • Look at void QWebEnginePage::triggerAction(WebAction action, bool) implementation

    void InContextPreviewView::onOpenLinkInNewWindow( bool )
    const auto & contextMenuData = page()->contextMenuData();
    if( contextMenuData.isValid() && contextMenuData.linkUrl().isValid() )

Log in to reply