Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><strong>how QGraphicsItem knows when the bounding rect changes?</strong></li> </ul> <p>I think <em>you know</em>. Let's say you have a QGraphicsItemGroup aggregating several child items, and you want to show only one child at a time. The bounding rect of the group item needs to be the same as the bounding rect of the currently selected item:</p> <pre><code>QRectF MyItemGroup::boundingRect() const { QRectF rect; if (currentItem_) { rect = currentItem_-&gt;boundingRect(); } return rect; } </code></pre> <p>Suppose you have a method to change which one of the children has to be shown:</p> <pre><code>void MyItemGroup::setCurrentItem(MyItem * item) { if (list_of_items_.contains(item)) { prepareGeometryChange(); currentItem_ = item; } } </code></pre> <p>If you comment out prepareGeometryChange, the view will not ask again for MyItemGroup's bounding rect, and the update of the item (triggered somewhere else) will involve the wrong rect.</p> <ul> <li><strong>how it knows when to call update()?</strong></li> </ul> <p>According with the QGraphicsItem sources, inside the <code>prepareGeometry</code> method update is called only in two cases:</p> <ol> <li>if someone is connected to the <code>changed</code> signal</li> <li>if the scene has no views</li> </ol> <p>more details <a href="http://qt.gitorious.org/qt/qt/blobs/4.8/src/gui/graphicsview/qgraphicsitem.cpp" rel="noreferrer">here</a></p> <ul> <li><strong>Are you ever supposed to call update() yourself after calling prepareGeometryChange() and then changing the bounding rectangle?</strong></li> </ul> <p>I think the answer is <em>No</em>. Aside from the call to <code>update</code>, <code>prepareGeometryChange</code> marks as dirty the item region on the scene, causing a repaint of the region itself. In my experience this sufficed in the 100% of the cases, so I didn't need to call update().</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload