forked from feiyangqingyun/QWidgetDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.cpp
66 lines (59 loc) · 2.13 KB
/
widget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
{
ui->setupUi(this);
this->initForm();
}
Widget::~Widget()
{
delete ui;
}
void Widget::initForm()
{
#ifdef webkit
QWebSettings *webSetting = QWebSettings::globalSettings();
webSetting->setAttribute(QWebSettings::JavascriptEnabled, true);
webSetting->setAttribute(QWebSettings::PluginsEnabled, true);
webSetting->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
#else
QWebEngineSettings *webSetting = QWebEngineSettings::globalSettings();
webSetting->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
webSetting->setAttribute(QWebEngineSettings::PluginsEnabled, true);
webSetting->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, true);
#endif
#ifdef webkit
webView = new QWebView;
webView1 = new QWebView;
webView2 = new QWebView;
webView3 = new QWebView;
#else
webView = new QWebEngineView;
webView1 = new QWebEngineView;
webView2 = new QWebEngineView;
webView3 = new QWebEngineView;
#endif
ui->gridLayout->addWidget(webView, 0, 0);
ui->gridLayout->addWidget(webView1, 0, 1);
ui->gridLayout->addWidget(webView2, 1, 0);
ui->gridLayout->addWidget(webView3, 1, 1);
webView->load(QUrl("file:///" + qApp->applicationDirPath() + "/gauge.html"));
webView1->load(QUrl("file:///" + qApp->applicationDirPath() + "/gauge.html"));
webView2->load(QUrl("file:///" + qApp->applicationDirPath() + "/gauge.html"));
webView3->load(QUrl("file:///" + qApp->applicationDirPath() + "/gauge.html"));
}
void Widget::on_horizontalSlider_valueChanged(int value)
{
QString js = QString("setGaugeValue(%1)").arg(value);
#ifdef webkit
webView->page()->mainFrame()->evaluateJavaScript(js);
webView1->page()->mainFrame()->evaluateJavaScript(js);
webView2->page()->mainFrame()->evaluateJavaScript(js);
webView3->page()->mainFrame()->evaluateJavaScript(js);
#else
webView->page()->runJavaScript(js);
webView1->page()->runJavaScript(js);
webView2->page()->runJavaScript(js);
webView3->page()->runJavaScript(js);
#endif
}