QGraphicsItem 绘制延迟 [英] QGraphicsItem paint delay

查看:88
本文介绍了QGraphicsItem 绘制延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是什么原因?当我放大 QGraphicsView 并移动 QGraphicsItem 时,我得到了这个奇怪的结果.如果我再次缩放或平移视图或者我专注于其他小部件,它会更新.我使用 PySide.而painter函数就是这个

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)

为什么即使对于这个基本的绘制事件也会发生这种情况?如果没有 Pen,则不会出现此问题.如果我增加笔的宽度,这个问题就会非常明显.

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.

推荐答案

我遇到了同样的问题.这是我的解决方案:

I had the same problem. This is my solution:

正如@Nathan Mooth 所说,问题是我在 boundingRect 之外绘制,所以我只绘制了圆角矩形(我在 paint() 方法中绘制的)10 个单位widthheight 小于 boundingRect:

As @Nathan Mooth said, the problem was that I was drawing outside of the boundingRect, so I just made my rounded rectangle(what I'm drawing in the paint() method) 10 units width and height less than the boundingRect:

 # Setup Rect
        frameRect = self.boundingRect()
        frameRect.setWidth(self.boundingRect().width() - 10)
        frameRect.setHeight(self.boundingRect().height() - 10)

这是之前的样子(GIF):

这是现在的样子(GIF)

注意:我添加了颜色选择并更改了阴影的颜色.所以看起来有点不同.

Note: I added color selection and changed the color of the drop shadow. So it looks a bit different.

这篇关于QGraphicsItem 绘制延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆