Priority: P3: Somewhat important
Affects Version/s: 5.7.1, 5.8.0
Fix Version/s: None
Component/s: Widgets: GraphicsView
Environment:Tested on Linux with Qt-5.8 (git), Qt-5.7 and 5.6
As initially reported here:
When moving an item that uses itemChange() to update it's parent pos() and it's own pos(), the item pos is not updated correctly.
See attached file to reproduce the problem.
Here is my use-case:
An item has "handles" child items, when the user moves around an handles, the parent item update it's geometry and position accordingly. Simple concept to let the user change an item geometry by dragging handles.
Imagine, you're using a drawing application, you select a circle and 5 handles appear on the screen, one in each corner to resize the circle, and one in the center to move the circle around.
The way i implement it is to let the circle item filter an handle item's 'itemChange()' notification. This work nicely for resizing handles, but fails for the 'move handle'. Here is the simplified pseudo code:
After banging my head for a while, i finally pin-pointed what I think is the problem:
This is related to how items are moved in qt5/qtbase/src/widgets/graphicsview/qgraphicsitem.cpp. When a move begins, the 'initial position' of the item is stored in the scene. This initial position is simply the value of item->pos(), which is in parent's item CS:
As the move goes on, the item's pos is updated based on this 'initial position' (expressed in an outdated parent's CS) and the parent position relative to the item's position:
Basically the above 3 lines would be correct only and only if the initialPositions were expressed in a dynamic way, that is, if they were independent of the parent's CS since it can change during the move.
The following pseudo-code modifications fixes that:
This modification fixes my use-cases, and doesn't seem to break the "40000 chips" and other demo/example.
The scene's private 'movingItemsInitialPositions' is only set/used by QGI::mouseMoveEvent() and cleared by QGI::mouseReleaseEvent(), so this is not an invasive change
So my chain of question is:
- Is changing the item's parent position in an item's itemChange() a supported feature?
- if it is, then isn't there a bug in qgraphicsitem.ccp as i described above?
- if positive, is the above fix correct and would you accept this sort of things if i push that to gerrit?
|For Gerrit Dashboard: QTBUG-58988|
|186290,3||QGraphicsItem: Fix moving items when itemChange() changes parent pos||dev||qt/qtbase||Status: ABANDONED||0||0|