Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QWebEngineView createWindow

Tags:

qt

qtwebengine

OK bending my brain trying to make sense of QWebEngine.

I understand the concept of implementing virtual functions but I'm unsure how to get the url that the user has clicked being a newTab/newWindow link that a page or view has requested.

QWebEngineView * WebEngineTabView::createWindow(QWebEnginePage::WebWindowType type)
{
// signal Main window for a new view( @URL )
emit requestNewTab(page()->requestedUrl());
}

This is for an educational GPL browser app Any help greatly appreciated

like image 533
ArchNemSyS Avatar asked Nov 18 '25 16:11

ArchNemSyS


1 Answers

Did you saw how this done in the demobrowser example?

QWebEnginePage *WebPage::createWindow(QWebEnginePage::WebWindowType type)
{
    if (type == QWebEnginePage::WebBrowserTab) {
        return mainWindow()->tabWidget()->newTab()->page();
    } else if (type == QWebEnginePage::WebBrowserWindow) {
        BrowserApplication::instance()->newMainWindow();
        BrowserMainWindow *mainWindow = BrowserApplication::instance()->mainWindow();
        return mainWindow->currentTab()->page();
    } else {
        PopupWindow *popup = new PopupWindow(profile());
        popup->setAttribute(Qt::WA_DeleteOnClose);
        popup->show();
        return popup->page();
    }
}

If you still want to delegate this work, notifying the mainwindow/app/whatever, you probably can intercept clicks and store links, but I'm not sure about calls order, plus you have to pay attention for cases when requested window is just a "new tab" (an empty tab without url):

bool WebPage::acceptNavigationRequest(const QUrl & url, NavigationType type, bool isMainFrame)
{
    switch( type )
    {
        case QWebEnginePage::NavigationTypeLinkClicked:
        {
            mLastClickedLink = url; //-- clear it in WebPage::createWindow
            return true;
        }
        default:
            return QWebEnginePage::acceptNavigationRequest( url, type, isMainFrame );
    }
}
like image 68
sendevent Avatar answered Nov 21 '25 18:11

sendevent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!