#2
hxw0517141072016-07-12 09:30
|
#ifndef WEBVIEWTEST001_H
#define WEBVIEWTEST001_H
#include <QtWebKitWidgets/QWebView>
#include <QtWebKitWidgets/QWebFrame>
class WebViewTest001 : public QWebView
{
Q_OBJECT
public:
WebViewTest001(QWidget *parent = 0);
~WebViewTest001();
protected:
bool eventFilter(QObject *obj, QEvent *ev);
};
#endif // WEBVIEWTEST001_H
#include "webviewtest001.h"
#include "qcoreevent.h"
#include "qevent.h"
#include "QtWebKitWidgets\QWebFrame"
#include <QMessageBox>
#ifdef _DEBUG
#pragma comment(lib,"Qt5Widgetsd.lib")
#pragma comment(lib,"Qt5WebKitWidgetsd.lib")
#pragma comment(lib, "Qt5WebKitd.lib")
#else
#pragma comment(lib,"Qt5Widgets.lib")
#pragma comment(lib,"Qt5WebKitWidgets.lib")
#pragma comment(lib, "Qt5WebKit.lib")
#endif
WebViewTest001::WebViewTest001(QWidget *parent)
: QWebView(parent)
{
installEventFilter(this);
// For WebPage
page()->installEventFilter(this);
// For WebFrame
page()->mainFrame()->installEventFilter(this);
}
WebViewTest001::~WebViewTest001()
{
}
bool WebViewTest001::eventFilter(QObject *obj, QEvent *ev)
{
if (ev->type() == QEvent::TouchBegin)
{
//QMessageBox::information(this, QStringLiteral("TouchBegin"), QStringLiteral("TouchBegin"));
}
if (ev->type() == QEvent::TouchUpdate)
{
//QMessageBox::information(this, QStringLiteral("TouchUpdate"), QStringLiteral("TouchUpdate"));
}
if (ev->type() == QEvent::TouchEnd)
{
//QMessageBox::information(this, QStringLiteral("TouchEnd"), QStringLiteral("TouchEnd"));
//QDesktopServices::openUrl(url);
}
QWebView::eventFilter(obj,ev);
return false;
}
#include "webviewtest001.h"
#include <QtWidgets/QApplication>
#include <QComboBox>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
WebViewTest001 w;
w.setWindowFlags(Qt::FramelessWindowHint);
w.setGeometry(0,0,1280,720);
w.load(QUrl("http://202.108.22.5:80/"));//百度
QComboBox cb(&w);
cb.addItem(QString::fromLocal8Bit("111"));
cb.addItem(QString::fromLocal8Bit("222"));
cb.addItem(QString::fromLocal8Bit("333"));
cb.show();
//cb.showPopup();
w.show();
return a.exec();
}
现在做的项目要兼容win10平板,加载网页的控件qwebview不响应触屏,在下拉控件qcombobox下拉时qwebview能响应一次,是什么原因呢