QGraphicsItem paint delay

帅比萌擦擦* 提交于 2019-12-11 07:23:07

问题


What could be the possible reason for this? When i zoom in the QGraphicsView and move the QGraphicsItem, I get this weird result. It does update if I zoom or pan the View again or if I focus on other widgets. Im using PySide. And the painter function is this

def paint(self, painter, option, widget):
    if self.isSelected():
        brush = self.highlight_brush
        pen = self.highlight_pen
    else:
        brush = self.dormant_brush
        pen = self.dormant_pen

    painter.setBrush(brush)
    painter.setPen(pen)

    painter.drawRect(0, 0, 100, 100)

Why does this happen even for this basic paint event? This problem is not seen if there is no Pen. If I increase the pen width, this issue is disturbingly visible.


回答1:


I don't know the actual solution for this rendering artifacts. But, updating the view during mouseMoveEvent did fix the issue.

 def mouseMoveEvent(self, event):
    QGraphicsView.mouseMoveEvent(self, event)
    if self.scene().selectedItems():
        self.update()



回答2:


The error you are seeing is probably because parts of what you are drawing are outside the bounding rectangle. My guess is you are using the same values to calculate the rectangle you are drawing as you are to calculate the bounding rectangle. Applying a pen then will make the drawn rectangle wider than the bounds and so will result in the smearing you are seeing.



来源:https://stackoverflow.com/questions/42620601/qgraphicsitem-paint-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!