PDA

View Full Version : specific painting for just one QGraphicsItem



jano_alex_es
23rd March 2011, 23:37
Hello, I'm having the next painting code in a QGraphicsPixmapItem:


void CFloorMagnet::paint ( QPainter * painter, const QStyleOptionGraphicsItem*
option, QWidget * widget)
{
if(painEllipses)
{
painter->drawEllipse(QPointF(m_iWidth/2, m_iHeight/2),
m_rCurrentLineDistance1, m_rCurrentLineDistance1);
painter->drawEllipse(QPointF(m_iWidth/2, m_iHeight/2),
m_rCurrentLineDistance2, m_rCurrentLineDistance2);
painter->drawEllipse(QPointF(m_iWidth/2, m_iHeight/2),
m_rCurrentLineDistance3, m_rCurrentLineDistance3);
}

QGraphicsPixmapItem::paint(painter, option, widget);
}


it creates three ellipses moving around the pixmap.

painEllipses variable changes between true-false each 5000 msecs. So, during five seconds I will have the ellipses on the screen and during another five it only draws the pixmap.

As I'm using QGraphicsView::MinimalViewportUpdate mode, I needed to make bigger the boundingrect in order to make possible that drawing.

But, when I execute the code the QGraphicsView starts to calculate what doesn't be to be redraw and the first time the painEllipses is false, the ellipses disappear. The second time the ellipses dissapear too but the paint event is called less times and the third try it does not enter. So I have the ellipses on the screen because there is no redraw.

I can solve if using QGraphicsView::FullViewportUpdate. But due to performance problems QGraphicsView::MinimalViewportUpdate is a must in my view.

Do you know any way to disable that "smart thinking" just for this item?

Thanks!

wysota
24th March 2011, 01:12
Do you call update() when you change the value of painEllipses?