3 个解决方案
#1
现在做的项目要兼容win10平板,加载网页的控件qwebview不响应触屏,在下拉控件qcombobox下拉时qwebview能响应一次,是什么原因呢
#2
你好
我也遇到了类似的问题,请问你解决了吗
我也遇到了类似的问题,请问你解决了吗
#3
bool WebViewTest001::eventFilter(QObject *obj,QEvent *event)
{
//QMessageBox::information(NULL,"length",""+event->type(),NULL);
switch (event->type()) {
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
if (touchPoints.length()==1)
{
//label2.append("length()==1\n");
if (multiTouchStart)
{
multiTouchStart=false;
/*
double pointListArea1=ploygon_area(pointList1);
double pointListArea2=ploygon_area(pointList2);
label2.append("pointList1:");
foreach (const QPoint &point1, pointList1)
{
char point1Str[20]={0};
sprintf(point1Str,"%d,%d;",point1.x(),point1.y());
label2.append(point1Str);
}
char str1[50]={0};
sprintf(str1,"pointList1length:%d;\n",pointList1.length());
label2.append(str1);
foreach (const QPoint &point2, pointList2)
{
char point2Str[20]={0};
sprintf(point2Str,"%d,%d;",point2.x(),point2.y());
label2.append(point2Str);
}
char str2[50]={0};
sprintf(str2,"pointList2length:%d;\n",pointList2.length());
label2.append(str2);
char resultStr[255]={0};
sprintf(resultStr,"result1:%f,result2:%f;\n",pointListArea1,pointListArea2);
label2.append(QString::fromLocal8Bit(resultStr));
if (pointListArea2>pointListArea1*1.1)
{
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
if (pointListArea2<pointListArea1*0.9)
{
char temp[255] = {0};
sprintf (temp, "zoomOut()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
*/
int width1=multiTouchStartPoint1.x()-multiTouchStartPoint2.x();
int height1=multiTouchStartPoint1.y()-multiTouchStartPoint2.y();
int width2=multiTouchEndPoint1.x()-multiTouchEndPoint2.x();
int height2=multiTouchEndPoint1.y()-multiTouchEndPoint2.y();
double result1=sqrt(double(width1*width1) + (height1*height1));
double result2=sqrt(double(width2*width2) + (height2*height2));
// char resultStr[255]={0};
// sprintf(resultStr,"result1:%f,result2:%f;\n%d,%d;%d,%d;\n%d,%d;%d,%d;\n)",result1,result2,multiTouchStartPoint1.x(),
// multiTouchStartPoint1.y(),multiTouchStartPoint2.x(),multiTouchStartPoint2.y(),multiTouchEndPoint1.x(),
// multiTouchEndPoint1.y(),multiTouchEndPoint2.x(),multiTouchEndPoint2.y());
// label2.append(QString::fromLocal8Bit(resultStr));
if (result2>result1+10)
{
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
if (result2<result1-10)
{
char temp[255] = {0};
sprintf (temp, "zoomOut()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
}
else
{
if (event->type() == QEvent::TouchBegin)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
if (touchBeginTimerIsStop)
{
firstTouchPoint=it->pos().toPoint();
touchBeginTimerIsStop=false;
touchBeginTimer.start(500);
}
else
{
touchBeginTimer.stop();
touchBeginTimerIsStop=true;
secondTouchPoint=it->pos().toPoint();
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
//QEvent *event2=new QMouseEvent(QEvent::Enter,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
//QCoreApplication::sendEvent(focusWidget(),event2);
delete event;
//delete event2;
}
if (event->type() == QEvent::TouchUpdate)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseMove,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
delete event;
}
if (event->type() == QEvent::TouchEnd)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonRelease,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
delete event;
}
}
}
if (touchPoints.length()>=2)
{
//label2.append("length()>=2\n");
if (!multiTouchStart)
{
//label2.append("record 1\n");
multiTouchStart=true;
int i=1;
pointList1.clear();
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
// pointList1.push_back(touchPoint.pos().toPoint());
// char pointStr[20]={0};
// sprintf(pointStr,"%d,%d;\n",touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
//
// label2.append(pointStr);
if (1==i)
{
multiTouchStartPoint1=touchPoint.pos().toPoint();
//label2.append("record 1-1\n");
}
else if (2==i)
{
multiTouchStartPoint2=touchPoint.pos().toPoint();
//label2.append("record 1-1\n");
}
else if (i>2)
{
break;
}
i++;
}
}
else
{
//label2.append("record 2\n");
pointList2.clear();
int i=1;
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
// pointList2.push_back(touchPoint.pos().toPoint());
// char pointStr[20]={0};
// sprintf(pointStr,"%d,%d;\n",touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
//
// label2.append(pointStr);
if (1==i)
{
multiTouchEndPoint1=touchPoint.pos().toPoint();
//label2.append("record 2-1\n");
}
else if (2==i)
{
multiTouchEndPoint2=touchPoint.pos().toPoint();
continue;
//label2.append("record 2-2\n");
}
else if (i>2)
{
break;
}
i++;
}
}
}
//
// QString qs;
// int i=1;
// foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
// {
// char temp[20]={0};
//
// sprintf(temp,"%d:%d,%d;\n",i++,touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
// qs.append(temp);
// }
//
// label.setText(qs);
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
switch (touchPoint.state()) {
case Qt::TouchPointStationary:
continue;
default:
{
}
break;
}
}
break;
}
default:
return QWidget::event(event);
}
return true;
}
我写的自定义类,解决了触屏响应的问题
{
//QMessageBox::information(NULL,"length",""+event->type(),NULL);
switch (event->type()) {
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
if (touchPoints.length()==1)
{
//label2.append("length()==1\n");
if (multiTouchStart)
{
multiTouchStart=false;
/*
double pointListArea1=ploygon_area(pointList1);
double pointListArea2=ploygon_area(pointList2);
label2.append("pointList1:");
foreach (const QPoint &point1, pointList1)
{
char point1Str[20]={0};
sprintf(point1Str,"%d,%d;",point1.x(),point1.y());
label2.append(point1Str);
}
char str1[50]={0};
sprintf(str1,"pointList1length:%d;\n",pointList1.length());
label2.append(str1);
foreach (const QPoint &point2, pointList2)
{
char point2Str[20]={0};
sprintf(point2Str,"%d,%d;",point2.x(),point2.y());
label2.append(point2Str);
}
char str2[50]={0};
sprintf(str2,"pointList2length:%d;\n",pointList2.length());
label2.append(str2);
char resultStr[255]={0};
sprintf(resultStr,"result1:%f,result2:%f;\n",pointListArea1,pointListArea2);
label2.append(QString::fromLocal8Bit(resultStr));
if (pointListArea2>pointListArea1*1.1)
{
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
if (pointListArea2<pointListArea1*0.9)
{
char temp[255] = {0};
sprintf (temp, "zoomOut()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
*/
int width1=multiTouchStartPoint1.x()-multiTouchStartPoint2.x();
int height1=multiTouchStartPoint1.y()-multiTouchStartPoint2.y();
int width2=multiTouchEndPoint1.x()-multiTouchEndPoint2.x();
int height2=multiTouchEndPoint1.y()-multiTouchEndPoint2.y();
double result1=sqrt(double(width1*width1) + (height1*height1));
double result2=sqrt(double(width2*width2) + (height2*height2));
// char resultStr[255]={0};
// sprintf(resultStr,"result1:%f,result2:%f;\n%d,%d;%d,%d;\n%d,%d;%d,%d;\n)",result1,result2,multiTouchStartPoint1.x(),
// multiTouchStartPoint1.y(),multiTouchStartPoint2.x(),multiTouchStartPoint2.y(),multiTouchEndPoint1.x(),
// multiTouchEndPoint1.y(),multiTouchEndPoint2.x(),multiTouchEndPoint2.y());
// label2.append(QString::fromLocal8Bit(resultStr));
if (result2>result1+10)
{
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
if (result2<result1-10)
{
char temp[255] = {0};
sprintf (temp, "zoomOut()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
}
else
{
if (event->type() == QEvent::TouchBegin)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
if (touchBeginTimerIsStop)
{
firstTouchPoint=it->pos().toPoint();
touchBeginTimerIsStop=false;
touchBeginTimer.start(500);
}
else
{
touchBeginTimer.stop();
touchBeginTimerIsStop=true;
secondTouchPoint=it->pos().toPoint();
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
//QEvent *event2=new QMouseEvent(QEvent::Enter,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
//QCoreApplication::sendEvent(focusWidget(),event2);
delete event;
//delete event2;
}
if (event->type() == QEvent::TouchUpdate)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseMove,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
delete event;
}
if (event->type() == QEvent::TouchEnd)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonRelease,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
delete event;
}
}
}
if (touchPoints.length()>=2)
{
//label2.append("length()>=2\n");
if (!multiTouchStart)
{
//label2.append("record 1\n");
multiTouchStart=true;
int i=1;
pointList1.clear();
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
// pointList1.push_back(touchPoint.pos().toPoint());
// char pointStr[20]={0};
// sprintf(pointStr,"%d,%d;\n",touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
//
// label2.append(pointStr);
if (1==i)
{
multiTouchStartPoint1=touchPoint.pos().toPoint();
//label2.append("record 1-1\n");
}
else if (2==i)
{
multiTouchStartPoint2=touchPoint.pos().toPoint();
//label2.append("record 1-1\n");
}
else if (i>2)
{
break;
}
i++;
}
}
else
{
//label2.append("record 2\n");
pointList2.clear();
int i=1;
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
// pointList2.push_back(touchPoint.pos().toPoint());
// char pointStr[20]={0};
// sprintf(pointStr,"%d,%d;\n",touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
//
// label2.append(pointStr);
if (1==i)
{
multiTouchEndPoint1=touchPoint.pos().toPoint();
//label2.append("record 2-1\n");
}
else if (2==i)
{
multiTouchEndPoint2=touchPoint.pos().toPoint();
continue;
//label2.append("record 2-2\n");
}
else if (i>2)
{
break;
}
i++;
}
}
}
//
// QString qs;
// int i=1;
// foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
// {
// char temp[20]={0};
//
// sprintf(temp,"%d:%d,%d;\n",i++,touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
// qs.append(temp);
// }
//
// label.setText(qs);
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
switch (touchPoint.state()) {
case Qt::TouchPointStationary:
continue;
default:
{
}
break;
}
}
break;
}
default:
return QWidget::event(event);
}
return true;
}
我写的自定义类,解决了触屏响应的问题
#1
现在做的项目要兼容win10平板,加载网页的控件qwebview不响应触屏,在下拉控件qcombobox下拉时qwebview能响应一次,是什么原因呢
#2
你好
我也遇到了类似的问题,请问你解决了吗
我也遇到了类似的问题,请问你解决了吗
#3
bool WebViewTest001::eventFilter(QObject *obj,QEvent *event)
{
//QMessageBox::information(NULL,"length",""+event->type(),NULL);
switch (event->type()) {
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
if (touchPoints.length()==1)
{
//label2.append("length()==1\n");
if (multiTouchStart)
{
multiTouchStart=false;
/*
double pointListArea1=ploygon_area(pointList1);
double pointListArea2=ploygon_area(pointList2);
label2.append("pointList1:");
foreach (const QPoint &point1, pointList1)
{
char point1Str[20]={0};
sprintf(point1Str,"%d,%d;",point1.x(),point1.y());
label2.append(point1Str);
}
char str1[50]={0};
sprintf(str1,"pointList1length:%d;\n",pointList1.length());
label2.append(str1);
foreach (const QPoint &point2, pointList2)
{
char point2Str[20]={0};
sprintf(point2Str,"%d,%d;",point2.x(),point2.y());
label2.append(point2Str);
}
char str2[50]={0};
sprintf(str2,"pointList2length:%d;\n",pointList2.length());
label2.append(str2);
char resultStr[255]={0};
sprintf(resultStr,"result1:%f,result2:%f;\n",pointListArea1,pointListArea2);
label2.append(QString::fromLocal8Bit(resultStr));
if (pointListArea2>pointListArea1*1.1)
{
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
if (pointListArea2<pointListArea1*0.9)
{
char temp[255] = {0};
sprintf (temp, "zoomOut()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
*/
int width1=multiTouchStartPoint1.x()-multiTouchStartPoint2.x();
int height1=multiTouchStartPoint1.y()-multiTouchStartPoint2.y();
int width2=multiTouchEndPoint1.x()-multiTouchEndPoint2.x();
int height2=multiTouchEndPoint1.y()-multiTouchEndPoint2.y();
double result1=sqrt(double(width1*width1) + (height1*height1));
double result2=sqrt(double(width2*width2) + (height2*height2));
// char resultStr[255]={0};
// sprintf(resultStr,"result1:%f,result2:%f;\n%d,%d;%d,%d;\n%d,%d;%d,%d;\n)",result1,result2,multiTouchStartPoint1.x(),
// multiTouchStartPoint1.y(),multiTouchStartPoint2.x(),multiTouchStartPoint2.y(),multiTouchEndPoint1.x(),
// multiTouchEndPoint1.y(),multiTouchEndPoint2.x(),multiTouchEndPoint2.y());
// label2.append(QString::fromLocal8Bit(resultStr));
if (result2>result1+10)
{
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
if (result2<result1-10)
{
char temp[255] = {0};
sprintf (temp, "zoomOut()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
}
else
{
if (event->type() == QEvent::TouchBegin)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
if (touchBeginTimerIsStop)
{
firstTouchPoint=it->pos().toPoint();
touchBeginTimerIsStop=false;
touchBeginTimer.start(500);
}
else
{
touchBeginTimer.stop();
touchBeginTimerIsStop=true;
secondTouchPoint=it->pos().toPoint();
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
//QEvent *event2=new QMouseEvent(QEvent::Enter,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
//QCoreApplication::sendEvent(focusWidget(),event2);
delete event;
//delete event2;
}
if (event->type() == QEvent::TouchUpdate)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseMove,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
delete event;
}
if (event->type() == QEvent::TouchEnd)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonRelease,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
delete event;
}
}
}
if (touchPoints.length()>=2)
{
//label2.append("length()>=2\n");
if (!multiTouchStart)
{
//label2.append("record 1\n");
multiTouchStart=true;
int i=1;
pointList1.clear();
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
// pointList1.push_back(touchPoint.pos().toPoint());
// char pointStr[20]={0};
// sprintf(pointStr,"%d,%d;\n",touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
//
// label2.append(pointStr);
if (1==i)
{
multiTouchStartPoint1=touchPoint.pos().toPoint();
//label2.append("record 1-1\n");
}
else if (2==i)
{
multiTouchStartPoint2=touchPoint.pos().toPoint();
//label2.append("record 1-1\n");
}
else if (i>2)
{
break;
}
i++;
}
}
else
{
//label2.append("record 2\n");
pointList2.clear();
int i=1;
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
// pointList2.push_back(touchPoint.pos().toPoint());
// char pointStr[20]={0};
// sprintf(pointStr,"%d,%d;\n",touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
//
// label2.append(pointStr);
if (1==i)
{
multiTouchEndPoint1=touchPoint.pos().toPoint();
//label2.append("record 2-1\n");
}
else if (2==i)
{
multiTouchEndPoint2=touchPoint.pos().toPoint();
continue;
//label2.append("record 2-2\n");
}
else if (i>2)
{
break;
}
i++;
}
}
}
//
// QString qs;
// int i=1;
// foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
// {
// char temp[20]={0};
//
// sprintf(temp,"%d:%d,%d;\n",i++,touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
// qs.append(temp);
// }
//
// label.setText(qs);
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
switch (touchPoint.state()) {
case Qt::TouchPointStationary:
continue;
default:
{
}
break;
}
}
break;
}
default:
return QWidget::event(event);
}
return true;
}
我写的自定义类,解决了触屏响应的问题
{
//QMessageBox::information(NULL,"length",""+event->type(),NULL);
switch (event->type()) {
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
if (touchPoints.length()==1)
{
//label2.append("length()==1\n");
if (multiTouchStart)
{
multiTouchStart=false;
/*
double pointListArea1=ploygon_area(pointList1);
double pointListArea2=ploygon_area(pointList2);
label2.append("pointList1:");
foreach (const QPoint &point1, pointList1)
{
char point1Str[20]={0};
sprintf(point1Str,"%d,%d;",point1.x(),point1.y());
label2.append(point1Str);
}
char str1[50]={0};
sprintf(str1,"pointList1length:%d;\n",pointList1.length());
label2.append(str1);
foreach (const QPoint &point2, pointList2)
{
char point2Str[20]={0};
sprintf(point2Str,"%d,%d;",point2.x(),point2.y());
label2.append(point2Str);
}
char str2[50]={0};
sprintf(str2,"pointList2length:%d;\n",pointList2.length());
label2.append(str2);
char resultStr[255]={0};
sprintf(resultStr,"result1:%f,result2:%f;\n",pointListArea1,pointListArea2);
label2.append(QString::fromLocal8Bit(resultStr));
if (pointListArea2>pointListArea1*1.1)
{
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
if (pointListArea2<pointListArea1*0.9)
{
char temp[255] = {0};
sprintf (temp, "zoomOut()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
*/
int width1=multiTouchStartPoint1.x()-multiTouchStartPoint2.x();
int height1=multiTouchStartPoint1.y()-multiTouchStartPoint2.y();
int width2=multiTouchEndPoint1.x()-multiTouchEndPoint2.x();
int height2=multiTouchEndPoint1.y()-multiTouchEndPoint2.y();
double result1=sqrt(double(width1*width1) + (height1*height1));
double result2=sqrt(double(width2*width2) + (height2*height2));
// char resultStr[255]={0};
// sprintf(resultStr,"result1:%f,result2:%f;\n%d,%d;%d,%d;\n%d,%d;%d,%d;\n)",result1,result2,multiTouchStartPoint1.x(),
// multiTouchStartPoint1.y(),multiTouchStartPoint2.x(),multiTouchStartPoint2.y(),multiTouchEndPoint1.x(),
// multiTouchEndPoint1.y(),multiTouchEndPoint2.x(),multiTouchEndPoint2.y());
// label2.append(QString::fromLocal8Bit(resultStr));
if (result2>result1+10)
{
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
if (result2<result1-10)
{
char temp[255] = {0};
sprintf (temp, "zoomOut()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
}
else
{
if (event->type() == QEvent::TouchBegin)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
if (touchBeginTimerIsStop)
{
firstTouchPoint=it->pos().toPoint();
touchBeginTimerIsStop=false;
touchBeginTimer.start(500);
}
else
{
touchBeginTimer.stop();
touchBeginTimerIsStop=true;
secondTouchPoint=it->pos().toPoint();
char temp[255] = {0};
sprintf (temp, "zoomIn()");
page()->mainFrame()->evaluateJavaScript(QString::fromLocal8Bit(temp));
}
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
//QEvent *event2=new QMouseEvent(QEvent::Enter,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
//QCoreApplication::sendEvent(focusWidget(),event2);
delete event;
//delete event2;
}
if (event->type() == QEvent::TouchUpdate)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseMove,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
delete event;
}
if (event->type() == QEvent::TouchEnd)
{
QList<QTouchEvent::TouchPoint>::const_iterator it= ((QTouchEvent*)event)->touchPoints().begin();
cursor().setPos(it->pos().toPoint());
QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonRelease,it->pos().toPoint(),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QCoreApplication::sendEvent(focusWidget(),event);
delete event;
}
}
}
if (touchPoints.length()>=2)
{
//label2.append("length()>=2\n");
if (!multiTouchStart)
{
//label2.append("record 1\n");
multiTouchStart=true;
int i=1;
pointList1.clear();
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
// pointList1.push_back(touchPoint.pos().toPoint());
// char pointStr[20]={0};
// sprintf(pointStr,"%d,%d;\n",touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
//
// label2.append(pointStr);
if (1==i)
{
multiTouchStartPoint1=touchPoint.pos().toPoint();
//label2.append("record 1-1\n");
}
else if (2==i)
{
multiTouchStartPoint2=touchPoint.pos().toPoint();
//label2.append("record 1-1\n");
}
else if (i>2)
{
break;
}
i++;
}
}
else
{
//label2.append("record 2\n");
pointList2.clear();
int i=1;
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
// pointList2.push_back(touchPoint.pos().toPoint());
// char pointStr[20]={0};
// sprintf(pointStr,"%d,%d;\n",touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
//
// label2.append(pointStr);
if (1==i)
{
multiTouchEndPoint1=touchPoint.pos().toPoint();
//label2.append("record 2-1\n");
}
else if (2==i)
{
multiTouchEndPoint2=touchPoint.pos().toPoint();
continue;
//label2.append("record 2-2\n");
}
else if (i>2)
{
break;
}
i++;
}
}
}
//
// QString qs;
// int i=1;
// foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
// {
// char temp[20]={0};
//
// sprintf(temp,"%d:%d,%d;\n",i++,touchPoint.pos().toPoint().x(),touchPoint.pos().toPoint().y());
// qs.append(temp);
// }
//
// label.setText(qs);
foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints)
{
switch (touchPoint.state()) {
case Qt::TouchPointStationary:
continue;
default:
{
}
break;
}
}
break;
}
default:
return QWidget::event(event);
}
return true;
}
我写的自定义类,解决了触屏响应的问题