title: Adding calls inside QgraphicsRectItem subclass triggers infinite redraw
body: <p>I have a hierarchy of object types, inheriting from a custom interface and <code>QGraphicsItem</code>.</p>
  
  <p>In hope of optimizing the code, I would like to inherit from <code>QGraphicsSomethingItem</code>. Example: rectangle</p>
  
  <pre><code>class RectangleItem : public Item, public QGraphicsItem
  {
    RectangleItem() : Item()  // Item initializes m_pen, m_brush
    {
      setFlags(QGraphicsItem::ItemIsMovable  |
           QGraphicsItem::ItemIsFocusable    |
           QGraphicsItem::ItemIsSelectable);
    }
    QRectF RectangleItem::boundingRect() const
    {
        return QRectF(-50, -50, 100, 100);
    }
    void RectangleItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
    {
      Q_UNUSED(option);
      Q_UNUSED(widget);
      setItemPen();   // calculates m_pen in class Item
      setItemBrush(); // calculates m_brush in class Item
      painter-&gt;setPen(m_pen);
      painter-&gt;setBrush(m_brush);
      painter-&gt;drawRect(boundingRect());
    }
  }
  </code></pre>
  
  <p>This works perfectly.</p>
  
  <p>Now trying the same thing but inheriting from <code>QGraphicsRectItem</code></p>
  
  <pre><code>class RectangleItem : public Item, public QGraphicsRectItem
  {
    RectangleItem() : Item()  // Item initializes m_pen, m_brush
    {
      setRect(-50, -50, 100, 100);
      setFlags(QGraphicsItem::ItemIsMovable  |
           QGraphicsItem::ItemIsFocusable    |
           QGraphicsItem::ItemIsSelectable);
    }
    QRectF RectangleItem::boundingRect() const
    {
        return QRectF(-50, -50, 100, 100);
    }
    void RectangleItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
    {
    //  setItemPen();   // calculates m_pen in class Item
    //  setItemBrush(); // calculates m_brush in class Item
      setPen(m_pen);
      setBrush(m_brush);
      QGraphicsRectItem::paint(painter, option, widget);
    }
  }
  </code></pre>
  
  <p>This creates an infinite loop<br>
  - a breakpoint on <code>setItemPen()</code> showed it kept calling it. So I removed it, along with <code>setItemBrush()</code>. (though I really need to set custom pen)<br>
  - a breakpoint on <code>setPen()</code> showed it kept calling it. So I removed it. Same with <code>setBrush()</code><br>
  - once there were no things being "set" inside paint, the paint worked.</p>
  
  <p>Of course this is not functional - I need to be able to set item properties, and my understanding is that the call to <code>paint()</code> - happening when a call to update the scene - would update he items. After all, my first example, inheriting from <code>QGraphicsItem</code>, works.</p>
  
  <p>I have found something similar in this <a href="https://stackoverflow.com/a/17338910/1217150">question</a> - but no answer on how to fix it, or no actual explanation why the call to set pen and brush causes a redraw. There is nothing in that code using any of the item's drawing properties, and even more - if I call <code>setPen(m_pen)</code> with the value from constructor, I see nothing to be recalculated...</p>
  
  <p>What triggers the object redraw and how can I avoid it ?</p>