Note that there are some explanatory texts on larger screens.

plurals
  1. POQt Adding children to a QGraphicsItem derivate in a QGraphicsScene do not show up
    primarykey
    data
    text
    <p>I subclassed QGraphicsItem twice: <em>RingCollection</em> is a kind of container item that should be filled with a list of child items of type <em>RingCollectionItem</em>. To achieve this, there is a populate() method, that (for testing) simply generates one item and sets its parent to the current collection.</p> <p>Now, when I add the item to the collection inside the populate method, it does not show up in the scene. When I add it directly , it's there. I'm quite puzzled (and frankly, reaching this minimal test case took me ages, cause I had no idea where to look for the problem...) So here it goes:</p> <p>Code in main (extract):</p> <pre><code>// works, both collection and item are drawn RingCollection collection(QPoint(0,0),150); RingCollectionItem newitem; newitem.setParentItem(&amp;collection); newitem.setPos(10.0, 10.0); scene.addItem(&amp;collection); </code></pre> <p>The other method:</p> <pre><code>//does not work: only the collection is drawn RingCollection collection(QPoint(0,0),150); collection.populate(); scene.addItem(&amp;collection); </code></pre> <p>and the <em>void populate()</em> method:</p> <pre><code>RingCollectionItem newitem; newitem.setParentItem(this); newitem.setPos(10.0, 10.0); </code></pre> <p>Maybe anyone can see what I'm missing, as far as I can tell both does basically the same thing. My best guess is that passing <em>this</em> somehow doesn't do what I expect it to, although I've seen examples do this... (In my understanding, <em>this</em> is a pointer to the current instance, please correct me if I got this wrong).</p> <p>Cheers, Louise</p> <p>PS: I tested that populate actually gets called, just in case. It does ;)</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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