'QWebEnginePage handle NewWindowRequest?
That the important line of code for understanding:
QWebEngineView *web = new QWebEngineView;
QWebEnginePage *page = new QWebEnginePage;
web->setPage(page);
page->load(QUrl("https://portal.premiertech.com/"));
and this is diplayed in normal QmainWindows like this
#include "fp.h"
fp::fp(QWidget *parent)
: QMainWindow(parent)
{
//définition et parametre de la page webview
web->setPage(page);
page->load(QUrl("https://portal.premiertech.com/"));
//parametre du tray icon
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
trayIcon->setIcon(QIcon(":/ico/favicon.ico"));
trayIcon->setToolTip("Pt Portal");
QMenu *traymenu = new QMenu(this);
QAction *viewWindow = new QAction(tr("Afficher Pt Portal"), this);
QAction *quitAction = new QAction(tr("Fermer Pt Portal"), this);
connect(viewWindow, SIGNAL(triggered()), this, SLOT(show()));
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
traymenu->addAction(viewWindow);
traymenu->addAction(quitAction);
trayIcon->setContextMenu(traymenu);
trayIcon->show();
//fenetre a l'intérieux du mainwindows et son layout
QWidget *inside = new QWidget;
QGridLayout *gl = new QGridLayout;
QPushButton *bt_next = new QPushButton;
bt_next->setIcon(QIcon(":/ico/next.png"));
QPushButton *bt_retour = new QPushButton;
bt_retour->setIcon(QIcon(":/ico/back.png"));
QPushButton *bt_refresh = new QPushButton;
bt_refresh->setIcon(QIcon(":/ico/refresh.png"));
QPushButton *bt_home = new QPushButton;
bt_home->setIcon(QIcon(":/ico/home.png"));
QPushButton *bt_masque = new QPushButton;
bt_masque->setIcon(QIcon(":/ico/hide.png"));
QPushButton *bt_quit = new QPushButton;
bt_quit->setIcon(QIcon(":/ico/quit.png"));
gl->addWidget(bt_masque,0,3);
gl->addWidget(bt_home,0,4);
gl->addWidget(bt_retour,0,5);
gl->addWidget(bt_next,0,6);
gl->addWidget(bt_refresh,0,7);
gl->addWidget(bt_quit,0,8);
gl->addWidget(web,1,0,10,11);
inside->setLayout(gl);
//définition des parametre de la fenetre principale
setCentralWidget(inside);
setMinimumSize(500, 350);
setWindowIcon(QIcon(":ico/favicon.ico"));
setWindowTitle(tr("Pt Portal"));
setFocus();
//conect bt
connect(bt_quit,SIGNAL(clicked()),this,SLOT(close()));
connect(bt_masque,SIGNAL(clicked()),this,SLOT(hide()));
connect(bt_masque,SIGNAL(clicked()),this,SLOT(nw()));
connect(bt_home,SIGNAL(clicked()),this,SLOT(home()));
connect(bt_next,SIGNAL(clicked()),this,SLOT(next()));
connect(bt_refresh,SIGNAL(clicked()),this,SLOT(refresh()));
connect(bt_retour,SIGNAL(clicked()),this,SLOT(retour()));
}
void fp::home()
{
page->load(QUrl("https://portal.premiertech.com/"));
}
void fp::refresh()
{
web->reload();
}
void fp::next()
{
web->forward();
}
void fp::retour()
{
web->back();
}
and actually i try to handle the posibily to open in new windows when requested by java i have try 2 method but nothing work
#1
connect(page,SIGNAL(newWindowRequested(QWebEngineNewWindowRequest)),this,SLOT(createWindow(QWebEngineNewWindowRequest)));
#2
connect(page,SIGNAL(newWindowRequested(QWebEngineNewWindowRequest)),this,SLOT(newwindow(QWebEngineNewWindowRequest)));
void mywindow::newwindow(QWebEngineNewWindowRequest *requestwindow)
QWidget *mywidget= new QWidget;
QGridLayout *mygridlayout= new QGridLayout;
QWebEngineView *mywebview= new QWebEngineView;
QWebEnginePage *mypage = new QWebEnginePage;
mywebview->setPage(mypage);
mygridlayout->addWidget(mywebview);
requestwindow->openIn(mypage); //and i also try mypage->load(requestwindow->requestedUrl());
mywidget->setLayout(mygridlayout);
mywidget->show();
all of this option result in this error when i try to open new windows requested by java or by the rigth click action OpeninNewWindows:
ASSERT: "event->reason() != Qt::PopupFocusReason" in file \Users\qt\work\qt\qtwebengine\src\webenginewidgets\render_widget_host_view_qt_delegate_widget.cpp, line 79
My question is how to handle it? The 2 option which I named above look good or it should be sommething else?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
