zoukankan      html  css  js  c++  java
  • QT-QWebEngineView-createWindow弹出页面解决

    首先要写一个继承QWebEngineView的类

    头文件:

    #ifndef WEBBROWSER_H
    #define WEBBROWSER_H
    
    #include <QWebEngineView>
    #include <QWidget>
    
    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 <QWidget>
    #include<QMessageBox>
    #include<QMainWindow>
    
    namespace 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 <QTimer>
    #include <QUrl>
    
    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);
    
    }

     另:

    QWebEngineView在QT Creator开发的时候网页加载特别慢,使用release方式即可解决,嗖嗖快

     

  • 相关阅读:
    node(3)MVC代码结构模式moogoDB的学习
    node(2)
    node (1)
    函数上下文的判断
    JSON解析
    原生ajax
    new 关键字
    String 截取字符串#中间的文本
    WARN警告:Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended
    在Java8的foreach()中使用break、continue
  • 原文地址:https://www.cnblogs.com/Netsharp/p/9260862.html
Copyright © 2011-2022 走看看