#include "mywidget.h"
#include "ui_mywidget.h"
#include "sslwebenginepage.h"
#include "config.h"
#include <mydialog.h>
#include <QPushButton>
#include <QWebEngineView>
#include <QApplication>
#include <QDesktopWidget>
#include <QDebug>
#include <QMessageBox>
#include <QKeyEvent>
MyWidget::MyWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::MyWidget)
{
ui->setupUi(this);
int width = QApplication::desktop()->width();
int height = QApplication::desktop()->height();
ui->setupUi(this);
this->resize(width, height);
this->setWindowFlags(Qt::FramelessWindowHint);
this-> setWindowIcon(QIcon(":/new/prefix1/logo.jpg"));
exitBtn = new QPushButton(this);
connect(exitBtn, SIGNAL(clicked(bool)), this, SLOT(exitBtnFun()));
//button->setFixedSize(30,30);
//button->move((width-button->width()),0);
exitBtn->setGeometry(width-(exitBtn->width()),0,60,60);
exitBtn->show();
Config *cfg = new Config();
cfg->set("s1", "url","https://www.baidu.com");
cfg->set("s1", "name", "智慧送达");
QString url = cfg->get("s1", "url");
QString name = cfg->get("s1", "name");
qDebug() <<"entrance url:" << url;
qDebug() <<"app_name :" << name;
if(!url.isEmpty()) {
QWebEngineView *webView = this->loadWebContent(url);
webView->resize(width, height);
exitBtn->raise();
webView->showFullScreen();
} else {
exitBtn->raise();
this->showConfigEdit(this);
}
}
void MyWidget::showConfigEdit(MyWidget *parent) {
MyDialog *dialog = new MyDialog(parent);
//dialog->setWindowFlag(Qt::FramelessWindowHint);
qDebug() << ">>> edit box will show";
dialog->show();
//dialog->raise();
}
QWebEngineView* MyWidget::loadWebContent(const QString url) {
QWebEngineView *webView = new QWebEngineView(this);
webView->setPage(new SslWebEnginePage());
webView->load(QUrl(url));
return webView;
}
void MyWidget::keyPressEvent(QKeyEvent* event) {
// if ((event->modifiers() == Qt::ControlModifier) && (event->key() == Qt::Key_A)) {
// QMessageBox::aboutQt(NULL, "aboutQt");
// } else {
// qDebug("no no no");
// }
if ((event->key() == Qt::Key_A)) {
QMessageBox::aboutQt(NULL, "aboutQt");
} else {
qDebug("hehe");
}
}
void MyWidget::exitBtnFun() {
QMessageBox msgBox;
msgBox.setWindowFlag(Qt::FramelessWindowHint);
msgBox.setWindowTitle(""); //设置窗口名
msgBox.setText(""); //设置文本
msgBox.setInformativeText("确定退出吗?"); //设置提示文本
msgBox.setStandardButtons(QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setButtonText(QMessageBox::Discard,"是"); //设置按钮文本
msgBox.setButtonText(QMessageBox::Cancel,"否");
msgBox.setDefaultButton(QMessageBox::Cancel); //设置缺省按钮
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Discard:
this->close();
break;
case QMessageBox::Cancel:
default:
break;
}
}
MyWidget::~MyWidget()
{
delete ui;
delete exitBtn;
}
使用Qt Web引擎嵌入H5应用框架源码,可以很方便的将web应用作为桌面应用。
3星 · 超过75%的资源 需积分: 42 197 浏览量
2019-03-09
12:28:02
上传
评论 2
收藏 3.53MB ZIP 举报
Astruries
- 粉丝: 17
- 资源: 21
最新资源
- 基于混沌集成决策树的电能质量复合扰动识别(注释完全,可直接运行)(文档加Matlab源码)
- 基于JAVA的打飞机游戏设计(程序).zip
- 随机优化智能配电网的双时间尺度随机优化调度(注释完全,可直接运行)(文档加Matlab源码)
- 多目标粒子群选址定容-main为主函数-含储能出力(注释完全,可直接运行)(文档加Matlab源码)
- fonepaw苹果恢复
- 基于主从博弈的主动配电网阻塞管理(注释完全,可直接运行)(文档加Matlab源码)
- 房地产公司信息化管理奖惩作业指引模版.doc
- 园区三方主体(注释完全,可直接运行)(文档加Matlab源码)
- 基于php+mysql+html+css超市管理系统答辩PPT.pptx
- 房地产公司信息化管理程序模版.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈