Below is the one I tried. Now the link opens in a new window.
But how do I make it open in a new tab.
I checked the link which was provided in the previous code. But as beginner, it's too much for me to understand.
#include "WebEnginePage.h"
WebEnginePage::WebEnginePage(QObject *parent)
: QWebEnginePage(parent)
{
connect(this,SIGNAL(urlChanged(QUrl)),this,SLOT(loadInTab(QUrl)));
}
WebEnginePage::~WebEnginePage()
{
}
void WebEnginePage::loadInTab(QUrl url)
{
qDebug()<<"Page : "<<url;
emit pageInNewTab(url);
}
#include "WebEngineView.h"
WebEngineView::WebEngineView(QWidget *parent)
: QWebEngineView(parent)
{
webPage = new WebEnginePage(this);
setPage(webPage);
setGeometry(0,35,dw.width(),dw.height()-35);
// connect(page(),SIGNAL(urlChanged(QUrl)),this,SLOT(loadInNewTab(QUrl)));
connect(page(),SIGNAL(pageInNewTab(QUrl)),this,SLOT(loadInNewTab(QUrl)));
hide();
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(onPageLoadFinished(bool)));
}
void WebEngineView::onPageLoadFinished(bool value)
{
qDebug()<<"WebEngineView::onPageLoadFinished";
show();
emit newTab(this);
}
WebEngineView::~WebEngineView()
{
}
WebEngineView *WebEngineView::createWindow(QWebEnginePage::WebWindowType type)
{
Q_UNUSED(type);
qDebug()<<"WebEngineView::createWindow";
WebEngineView *webView = new WebEngineView();
qDebug()<<"Index : "<<++index;
WebEnginePage *newWeb = new WebEnginePage(webView);
webView->setAttribute(Qt::WA_DeleteOnClose, true);
webView->setPage(newWeb);
//webView->show();
return webView;
}
void WebEngineView::loadInNewTab(QUrl url)
{
qDebug()<<"WebEngineView "<<index<<" : "<<url;
// createWindow(QWebEnginePage::WebBrowserTab);
}
int WebEngineView::getIndex() const
{
return index;
}
void WebEngineView::setIndex(int value)
{
index = value;
}
#include "TabWindow.h"
TabWindow::TabWindow(QWidget *parent)
: QMainWindow(parent)
{
weView = new WebEngineView(this);
weView->setGeometry(0,50,dw.width(),dw.height());
loadedUrl = QUrl("http://www.google.co.in");
//weView->load(QUrl(loadedUrl));
weView->webPage->load(loadedUrl);
QWidget *centralWidget = new QWidget(this);
tabWidget = new QTabWidget(centralWidget);
tabWidget->setTabsClosable(true);
//tabWidget->setElideMode(Qt::ElideRight);
tabWidget->setFixedSize(dw.width(),dw.height());
loadedUrl = QUrl("http://www.google.co.in");
tabWidget->addTab(weView,loadedUrl.host());
setCentralWidget(centralWidget);
currentIndex = 0;
weView->setIndex(currentIndex);
//weViewNew = new WebEngineView(this);
connect(weView,SIGNAL(newTab(WebEngineView&)),this,SLOT(loadNewTab(WebEngineView7)));
connect(tabWidget,SIGNAL(tabCloseRequested(int)),this,SLOT(closeTab(int)));
}
TabWindow::~TabWindow()
{
}
void TabWindow::closeTab(int index)
{
tabWidget->removeTab(index);
}
void TabWindow::loadNewTab(WebEngineView *webView)
{
//webView->show();
tabWidget->addTab(webView,webView->webPage->url().host());
//tabWidget->setCurrentIndex(currentIndex);
qDebug()<<"TabWindow::loadNewTab : ";
}