├── CustomStyle.h ├── README.md ├── main.cpp ├── map.html ├── testwebview.pro ├── widget.cpp ├── widget.h └── widget.ui /CustomStyle.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMSTYLE_H 2 | #define CUSTOMSTYLE_H 3 | #include 4 | #include 5 | class CustomStyle : public QProxyStyle 6 | { 7 | void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget = 0) const 8 | { 9 | if (element == QStyle::CE_CheckBox || 10 | element == QStyle::CE_RadioButton) { 11 | // option->styleObject->setProperty("_q_no_animation", true); 12 | } 13 | QProxyStyle::drawControl(element, option, painter, widget); 14 | } 15 | }; 16 | #endif // CUSTOMSTYLE_H 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Qt Website: http://www.heilqt.com 2 | ## Getting Started 3 | 4 | #### Building the module 5 | 6 | 7 | * Download or git clone the source code. 8 | 9 | * Put the source code in any directory you like 10 | 11 | * Go to top directory of the project in a terminal and run 12 | 13 | ``` 14 | qmake 15 | make 16 | ``` 17 | * Or use qtcreator IDE and build it 18 | 19 | ### Function about Baidu Map Api 20 | 21 | * http://developer.baidu.com/map/jsdemo.htm#i2_1 22 | 23 | ### Follow the csdn blog 24 | * http://blog.csdn.net/esonpo/article/details/9243027 25 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | #include "CustomStyle.h" 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | QApplication::setStyle(new CustomStyle()); 8 | Widget w; 9 | // playAudioFile("C:/Users/Administrator/Downloads/小苹果.mp3"); 10 | w.show(); 11 | 12 | return a.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /map.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 8 | 9 | 周边搜索 10 | 34 | 35 | 36 |
37 | 38 | 39 | 48 | -------------------------------------------------------------------------------- /testwebview.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2015-03-16T15:19:25 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui webkit 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets webkitwidgets 10 | 11 | TARGET = testwebview 12 | TEMPLATE = app 13 | 14 | 15 | SOURCES += main.cpp\ 16 | widget.cpp 17 | 18 | HEADERS += widget.h \ 19 | CustomStyle.h 20 | 21 | FORMS += widget.ui 22 | -------------------------------------------------------------------------------- /widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "ui_widget.h" 3 | #include 4 | #include "CustomStyle.h" 5 | #include 6 | #include 7 | #include 8 | 9 | Widget::Widget(QWidget *parent) : 10 | QWidget(parent), 11 | ui(new Ui::Widget) 12 | { 13 | ui->setupUi(this); 14 | QWebSettings *settings = QWebSettings::globalSettings(); 15 | settings->setAttribute(QWebSettings::PluginsEnabled, true);//允许插件 16 | settings->setAttribute(QWebSettings::JavascriptEnabled, true);//JavaScript 17 | settings->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);// 18 | settings->setAttribute(QWebSettings::JavascriptCanOpenWindows, true); 19 | settings->setFontFamily(QWebSettings::FixedFont,"幼圆"); 20 | 21 | ui->webView->setStyle(new CustomStyle()); 22 | ui->webView->load(QUrl("file:///D:/BigData/Qt-Tools/Demo/testwebview/map.html")); 23 | // ui->webView->load(QUrl("http://www.yicai.com/video/")); 24 | connect(ui->webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject())); 25 | 26 | } 27 | 28 | Widget::~Widget() 29 | { 30 | delete ui; 31 | } 32 | 33 | void Widget::on_pushButton_3_clicked() 34 | { 35 | onBtnCallJSClicked(); 36 | } 37 | void Widget::populateJavaScriptWindowObject() 38 | { 39 | ui->webView->page()->mainFrame()->addToJavaScriptWindowObject("Mywebkit", this); 40 | } 41 | void Widget::onBtnCallJSClicked() 42 | { 43 | QString allStr = QDateTime::currentDateTime().toString(); 44 | QStringList xylst = ui->lineEdit_2->text().split(","); 45 | QString strVal = QString("callfromqt(\"%1\",\"%2\",\"%3\",\"%4\");").arg(ui->lineEdit_3->text()).arg(ui->lineEdit->text()).arg(xylst.at(0)).arg(xylst.at(1)); 46 | qDebug()<<"onBtnCallJSClicked "<webView->page()->mainFrame()->evaluateJavaScript(strVal); 48 | } 49 | void Widget::onCallfromJs(QString str,QString str1,QString str2) 50 | { 51 | qDebug()<<"onCallfromJs"<< str<<"\n"< 5 | #include 6 | #include 7 | 8 | namespace Ui { 9 | class Widget; 10 | } 11 | 12 | class Widget : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit Widget(QWidget *parent = 0); 18 | ~Widget(); 19 | 20 | public slots: 21 | void populateJavaScriptWindowObject(); 22 | void onBtnCallJSClicked(); 23 | void onCallfromJs(QString str, QString str1, QString str2); 24 | private slots: 25 | void on_pushButton_3_clicked(); 26 | 27 | void on_pushButton_clicked(); 28 | 29 | void on_pushButton_2_clicked(); 30 | 31 | private: 32 | Ui::Widget *ui; 33 | }; 34 | 35 | #endif // WIDGET_H 36 | -------------------------------------------------------------------------------- /widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 974 10 | 604 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | about:blank 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 | 16777215 63 | 40 64 | 65 | 66 | 67 | 经纬度: 68 | 69 | 70 | 71 | 72 | 73 | 74 | 116.404,39.915 75 | 76 | 77 | 78 | 79 | 80 | 81 | 一起搜索 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | QWebView 95 | QWidget 96 |
QtWebKitWidgets/QWebView
97 |
98 |
99 | 100 | 101 |
102 | --------------------------------------------------------------------------------