QT-QWebEngineView-createWindow弹出页面解决
标签:explicit 头文件 icon etc pre view pac page names
首先要写一个继承QWebEngineView的类
头文件:
#ifndef WEBBROWSER_H
#define WEBBROWSER_H
#include
#include namespace netsharp {
class WebBrowser : public QWebEngineView
{
Q_OBJECT
public:
explicit WebBrowser(QWidget* parent = Q_NULLPTR);
protected:
/**
* @brief createWindow 在鼠标左键点击的时候会触发这个方法
* @param type
* @return
*/
QWebEngineView *createWindow(QWebEnginePage::WebWindowType type);
private :
};
}
#endif // WEBBROWSER_H
实现文件:
#include "webbrowser.h"
#include "MainWindow.h"
#include
#include
#includenamespace netsharp {
WebBrowser::WebBrowser(QWidget *parent) : QWebEngineView(parent)
{
}
QWebEngineView *WebBrowser::createWindow(QWebEnginePage::WebWindowType type)
{
WebBrowser *webbrowser = new WebBrowser(this);
QMainWindow *dialog = new QMainWindow() ;
dialog->setCentralWidget(webbrowser);
dialog->show();
return webbrowser;
}
}
主窗口调用文件代码(mainwindow.cpp)
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "WebBrowser.h"
#include "QSystemTrayIcon"
#include "QMessageBox"
#include
#include using namespace netsharp;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->webbrowser = new WebBrowser(this);
this->webbrowser->load(QUrl("http://beehive.gongsibao.com"));
this->setCentralWidget(this->webbrowser);
}
QT-QWebEngineView-createWindow弹出页面解决
标签:explicit 头文件 icon etc pre view pac page names
原文地址:https://www.cnblogs.com/Netsharp/p/9260862.html
评论