
Originally Posted by
T4ng10r
With reimplementing boundingRect I had lots of problems.
You didn't spend enough time on reading docs and analyzing given examples. Bounding rectangle is in item's coordinates so if you have rectangle item 20x20 then bounding rectangle returned by boundingRect() should QRectF(0,0,20,20).
Then drawing in paint() is also done in item's coordinates so doing like this:
painter->drawEllipse(pos().x(), pos().y(), 20, 20);
painter->drawEllipse(pos().x(), pos().y(), 20, 20);
To copy to clipboard, switch view to plain text mode
will cause painting outside the item's bounding rect, which effects you can see in your app. The proper code would be:
painter->drawEllipse(0, 0, 20, 20);
painter->drawEllipse(0, 0, 20, 20);
To copy to clipboard, switch view to plain text mode
assuming that bounding rect is at least with w=20, h=20;
Mainly positioning inside parents and on scene. In other situation I needed info about position of others scene object - but they weren't set till final object placement. QGraphicsWidget gave me ability to set size and pos and used them in other places without waiting for final scene placement where position and size are stored.
It is rather logical for me that item has no position if it is not added to any scene yet (or any parent) because there is no valid position. And notice that pos() is in parent's coordinates and scenePos() in scene's.
Bookmarks