【问题标题】:Qt- Moving a QGraphicsItem causes artifacts.Leaves trailes behindQt-移动 QGraphicsItem 会导致工件。留下痕迹
【发布时间】:2019-10-09 02:40:27
【问题描述】:

当我移动一个 QGraphicsItem 时,奇怪的工件留在后面。该项目的某些部分不渲染,其他渲染... 在 note.cpp 我有一个形状

QPainterPath Note::shape()const{
   QPainterPath path;
   //    path.addRect(0, 0, 50, 20);
   path.moveTo(0, -80.0);
   path.lineTo(0.0, 80.0);
   path.lineTo(80.0, 0.0);
   //    path.lineTo(75.0, -30.0);
   path.closeSubpath();
   return path;
}

在绘画功能中

QPointF *points = new QPointF[3];
points[0] = QPointF(0,-80);
points[1] = QPointF(0,80);
points[2] = QPointF(80,0);
painter->drawPolygon(points,3);

第一张图片显示当我启动应用程序时一切都很好。 第二张图片显示,当我用鼠标移动三角形时,它会被切片。其他时候它会留下一些痕迹并且不会渲染三角形的所有部分 这是该项目的 github 链接。 Github link

要复制,只需移动一个三角形。

【问题讨论】:

    标签: c++ qt qt5 mousemove qgraphicsitem


    【解决方案1】:

    QGraphicsItem 为提高效率仅重绘返回 boundingRect() 方法的部分,在您的情况下,QRect(0, 0, 80, 80) 仅返回一半必要区域,因为坐标 (0, -80) 在 boundingRect 之外。解决办法是:

    QRectF Note::boundingRect() const {
        return QRectF(0, -80, 80, 160) ;
        // or
        // return shape().boundingRect();
    }
    

    【讨论】:

    • 是的,你是对的。我需要告诉它我的形状的 x、y(原点),以及它的宽度、高度。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-28
    • 2021-07-07
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    相关资源
    最近更新 更多