nabroyan
nabroyan

Reputation: 3275

QGraphicsItem paint not called

I use QGraphicsView, QGrapichsScene and QGraphicsItem for drawing some charts. I have implemented QGraphicsItem::paint function for drawing text (values of charts), but it is not being called every time that is must draw something new. My paint function

    void CLabelItem::paint(QPainter *painter, 
const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget = 0*/)
{

    if ( GetValue() < 0 )
    {
        return;
    }
    painter->drawText(boundingRect(), m_value.toString());
}

So my question is - why QGraphicsItem::paint can be not called and how may I make it to be called?

Upvotes: 1

Views: 3415

Answers (2)

alexisdm
alexisdm

Reputation: 29886

You need to call QGraphicsItem::update() from the function that modify the m_value variable to trigger a repaint.

Upvotes: 3

Nicholas Smith
Nicholas Smith

Reputation: 11754

In general with Qt graphics items are drawn when paintEvent is called, and then you can handle painting inside a paint function.

Upvotes: 0

Related Questions