Gary_Cui_1st 2015-10-15 04:06 采纳率: 0%
浏览 4319

QLabel内嵌在一个widget窗体内,根据鼠标移动,移动labe,但是画面不刷新,

除非我拖动整个窗体的时候,画面才刷新

好难啊好难啊好难啊好难啊好难啊好难啊好难啊好难啊好难啊好难啊

 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;
}
  • 写回答

2条回答 默认 最新

  • lx624909677 2015-10-15 04:10
    关注

    在鼠标移动的槽函数里来update()一下widget

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题