forked from feiyangqingyun/QWidgetDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a056894
commit 9cf0de0
Showing
13 changed files
with
1,913 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<html> | ||
<head> | ||
<script> | ||
function onClicked() { | ||
//alert('hello'); | ||
document.getElementById('label').innerHTML = '确实不错哦'; | ||
objName_receiveData('type','data'); | ||
} | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<h1>Hello World</h1> | ||
<p>Hello World</p> | ||
<label id='label'>今天天气真棒</label> | ||
<input type="button" value="发送数据给Qt" onclick="onClicked()" /> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>ECharts</title> | ||
<script src="echarts.min.js"></script> | ||
</head> | ||
<body> | ||
<div id="main" style="height:500px;"></div> | ||
<script type="text/javascript"> | ||
var myChart = echarts.init(document.getElementById('main')); | ||
function setGaugeValue(value){ | ||
var option = { | ||
tooltip : { | ||
formatter: "{a} <br/>{b} : {c}%" | ||
}, | ||
toolbox: { | ||
feature: { | ||
restore: {}, | ||
saveAsImage: {} | ||
} | ||
}, | ||
series: [ | ||
{ | ||
name: '业务指标', | ||
type: 'gauge', | ||
detail: {formatter:'{value}%'}, | ||
data: [{value: value, name: '完成率'}] | ||
} | ||
] | ||
}; | ||
myChart.setOption(option); | ||
} | ||
window.onresize = myChart.resize; | ||
setGaugeValue(68); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "widget.h" | ||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
Widget w; | ||
w.show(); | ||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
QT += core gui | ||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
|
||
TARGET = miniblink | ||
TEMPLATE= app | ||
DESTDIR = $$PWD/../bin | ||
|
||
CONFIG += warn_off | ||
HEADERS += widget.h | ||
SOURCES += main.cpp widget.cpp | ||
FORMS += widget.ui | ||
|
||
INCLUDEPATH += $$PWD/miniblink | ||
include ($$PWD/miniblink/miniblink.pri) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#include "miniblink.h" | ||
#include "qapplication.h" | ||
#include "qdebug.h" | ||
|
||
void onLoadingFinish(wkeWebView, void *param, const wkeString, wkeLoadingResult result, const wkeString) | ||
{ | ||
//qDebug() << "onLoadingFinish" << result; | ||
//在注册函数的地方就已经传入了类指针 | ||
miniblink *widget = (miniblink *)param; | ||
//0 = WKE_LOADING_SUCCEEDED, 1 = WKE_LOADING_FAILED, 2 = WKE_LOADING_CANCELED | ||
widget->loadFinish(result == 0); | ||
} | ||
|
||
jsValue WKE_CALL_TYPE objName_receiveData(jsExecState es, void *param) | ||
{ | ||
if (0 == jsArgCount(es)) { | ||
return jsUndefined(); | ||
} | ||
|
||
//挨个取出参数,设定的通用方法,只有两个参数 | ||
jsValue arg0 = jsArg(es, 0); | ||
jsValue arg1 = jsArg(es, 1); | ||
if (!jsIsString(arg0)) { | ||
return jsUndefined(); | ||
} | ||
|
||
//在注册函数的地方就已经传入了类指针 | ||
miniblink *widget = (miniblink *)param; | ||
QString type = QString::fromStdString(jsToString(es, arg0)); | ||
QVariant data = QString::fromStdString(jsToString(es, arg1)); | ||
widget->receiveData(type, data); | ||
return jsUndefined(); | ||
} | ||
|
||
miniblink::miniblink(QWidget *parent) : QWidget(parent) | ||
{ | ||
//第一步先初始化动态库 | ||
init(); | ||
//第二步初始化浏览器控件 | ||
//创建一个浏览器控件,放入句柄 | ||
webView = wkeCreateWebWindow(WKE_WINDOW_TYPE_CONTROL, (HWND)this->winId(), 0, 0, this->width(), this->height()); | ||
//关联完成信号 | ||
wkeOnLoadingFinish(webView, onLoadingFinish, this); | ||
//设置浏览器控件可见 | ||
wkeShowWindow(webView, TRUE); | ||
//注册通用的接收数据的方法,一定要放在这里在网页加载前执行 | ||
wkeJsBindFunction("objName_receiveData", objName_receiveData, this, 2); | ||
} | ||
|
||
void miniblink::init() | ||
{ | ||
//全局只需要初始化一次 | ||
static bool isInit = false; | ||
if (!isInit) { | ||
isInit = true; | ||
//不同的构建套件位数加载不同的动态库 | ||
#ifdef Q_OS_WIN64 | ||
QString file = qApp->applicationDirPath() + "/miniblink_64.dll"; | ||
#else | ||
QString file = qApp->applicationDirPath() + "/miniblink.dll"; | ||
#endif | ||
const wchar_t *path = reinterpret_cast<const wchar_t *>(file.utf16()); | ||
wkeSetWkeDllPath(path); | ||
bool ok = wkeInitialize(); | ||
qDebug() << QString("init miniblink %1").arg(ok ? "ok" : "error"); | ||
} | ||
} | ||
|
||
void miniblink::release() | ||
{ | ||
wkeFinalize(); | ||
} | ||
|
||
void miniblink::resizeEvent(QResizeEvent *) | ||
{ | ||
wkeResize(webView, this->width(), this->height()); | ||
} | ||
|
||
void miniblink::loadFinish(bool ok) | ||
{ | ||
emit loadFinished(ok); | ||
} | ||
|
||
void miniblink::receiveData(const QString &type, const QVariant &data) | ||
{ | ||
emit receiveDataFromJs(type, data); | ||
} | ||
|
||
void miniblink::load(const QString &url, bool file) | ||
{ | ||
const char *temp = url.toLocal8Bit().data(); | ||
if (file) { | ||
wkeLoadFile(webView, temp); | ||
} else { | ||
wkeLoadURL(webView, temp); | ||
} | ||
} | ||
|
||
void miniblink::setHtml(const QString &html, const QString &baseUrl) | ||
{ | ||
wkeLoadHtmlWithBaseUrl(webView, html.toLocal8Bit().data(), baseUrl.toLocal8Bit().data()); | ||
} | ||
|
||
void miniblink::runJs(const QString &js) | ||
{ | ||
wkeRunJS(webView, js.toLocal8Bit().data()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef MINIBLINK_H | ||
#define MINIBLINK_H | ||
|
||
#include <QWidget> | ||
#include "wke.h" | ||
|
||
class miniblink : public QWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit miniblink(QWidget *parent = 0); | ||
|
||
//初始化资源 | ||
static void init(); | ||
//释放资源 | ||
static void release(); | ||
|
||
protected: | ||
//设置浏览器控件自动适应大小 | ||
void resizeEvent(QResizeEvent *); | ||
|
||
private: | ||
//浏览器控件对象 | ||
wkeWebView webView; | ||
|
||
signals: | ||
//网页载入完成 | ||
void loadFinished(bool ok); | ||
//收到网页发出来的数据 | ||
void receiveDataFromJs(const QString &type, const QVariant &data); | ||
|
||
public: | ||
//给回调用的函数 | ||
void loadFinish(bool ok); | ||
void receiveData(const QString &type, const QVariant &data); | ||
|
||
public slots: | ||
//加载网址或者本地文件 | ||
void load(const QString &url, bool file = false); | ||
//加载html内容 | ||
void setHtml(const QString &html, const QString &baseUrl); | ||
//执行js函数 | ||
void runJs(const QString &js); | ||
}; | ||
|
||
#endif // MINIBLINK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HEADERS += $$PWD/wke.h | ||
HEADERS += $$PWD/miniblink.h | ||
SOURCES += $$PWD/miniblink.cpp |
Oops, something went wrong.