除非我拖动整个窗体的时候,画面才刷新
好难啊好难啊好难啊好难啊好难啊好难啊好难啊好难啊好难啊好难啊
bool Widget::event(QEvent *event)
{
bool flipAction = false;
static float last_x = 0.0f;
static float touchBeginLastX = 0.0f;
int deltaX = 0;
float acceleration = 0.0f;
switch(event->type()) {
case QEvent::MouseButtonPress: {
flipAction = true;
m_time.start();
const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event);
last_x = mouseEvent->x();
touchBeginLastX = mouseEvent->x();
}
break;
case QEvent::MouseMove: {
flipAction = true;
const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event);
deltaX = mouseEvent->x() - last_x;
last_x = mouseEvent->x();
}
break;
case QEvent::MouseButtonRelease: {
flipAction = true;
int elapseTime = m_time.elapsed();
const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event);
deltaX = mouseEvent->x() - last_x;
acceleration = (mouseEvent->x() - touchBeginLastX) / elapseTime;
}
break;
default:
break;
}
if(flipAction) {
qDebug() << deltaX;
QPoint targetPos = ui->label->pos()+QPoint(deltaX,0);
qDebug() << ui->label->pos();
ui->label->setGeometry(targetPos.x(), targetPos.y(), ui->label->width(), ui->label->height());
// ui->label->move(targetPos);
ui->label->repaint();
repaint();
moveEvent(NULL);
}
return false;
}