试图找出是否发生触摸事件或者只是绘制它们。
bool MyWidget::event(QEvent *event)
{
switch (event->type())
{
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
QTouchEvent *touchEvent = static_cast(event);
if (touchEvent->touchPoints().count() == 2)
{
const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first();
const QTouchEvent::TouchPoint &touchPoint2 = touchEvent->touchPoints().last();
nx=touchPoint1.scenePos().x();
ny=touchPoint1.scenePos().y();
pix = QPixmap::grabWidget (this,nx,ny,1,1);
img = pix.toImage();
rgb = img.pixel(0,0);
color.setRgb(rgb);
drawBit=1;
}
break;
}
case QEvent::Paint:
return MyWidget::paintEvent( event);
break;
default:
return false;
break;
}
return true;
}
void MyWidget::paintEvent(QPaintEvent *event)
{
time_counter++;
for(i=0;(ired,b[i]->green,b[i]->blue,255), Qt::SolidPattern));
painter.drawEllipse(b[i]->x,b[i]->y,b[i]->w, b[i]->w);
painter.drawLine(b[i]->x+b[i]->w/2,b[i]->y+b[i]->w,b[i]->x+b[i]->w/2,b[i]->y+2*b[i]->w);
if(b[i]->ballDead==false)
b[i]->y+=b[i]->vy;
if(drawBit==1 && b[i]->red==color.red() && b[i]->green==color.green() && b[i]->blue==color.blue())
ballHit(i);
}
}
此代码显示如下错误: mywidget.cpp:116:47:错误:从“QEvent*”到“QPaintEvent*”的无效转换 mywidget.cpp:116:47: 错误: 初始化'virtual void MyWidget::paintEvent(QPaintEvent*)' 的参数 1 mywidget.cpp:116:47: 错误: void 值没有被忽略,因为它应该被忽略