PDA

View Full Version : New position not updated to the parent in QtGraphicsScene



Marnix
12th April 2010, 12:31
Hello,

I'm new in Qt and working on a project that uses QtGraphicsScene. I'm using Qt4.6.

I create a new QGraphicsRectItem with a QGraphicsItem as it parent.
When I then move the QGraphicsRectItem with moveBy or setRotation the parent still gets the old position of the QGraphicsRectItem. I've set the mouse to change shape when I hover over QGraphicsRectItem and it changes shape on the new and on the old position. When I ignore a mouse event in QGraphicsRectItem on the new position the parent does not get the mouse event. The parent but still receives events when i click on the old position.
I've enabled the ItemIsMovable, ItemIsSelectable, ItemSendsGeometryChanges, ItemSendsScenePositionChanges flags.
Is there something else i should do?

Thanks in advance.

Marnix

wysota
12th April 2010, 13:29
Can we see some code? Did you reimplement any of the methods from QGraphicsRectItem?

Marnix
13th April 2010, 14:24
Hello,

I partially solved my problem. I had reimplemented the shape function for QGraphicsRectItem (I only want the border and not filled) and QGraphicsScene. In QGraphicsScene I called the the reimplemented QGraphicsRectItem shape and did not translate this shape by the moved distance. So after the translation of the QPainterPath the parent gets the the mouse events. However I also need to rotate and there does not exist by my knowledge a function to rotate a QPainterPath. I'll think there should exit move and rotation (in local coordinates) that also adapt the shape so parents can access the shape of there children without the need for translation or rotation. I'll try to re implement everything with QTransform matrices.

wysota
13th April 2010, 14:44
I think you are approaching the problem from the wrong end. boundingRect() and shape() should return an invariant coordinates of the item. If a car is 3 metres long, if it turns right it is still 3 metres long. If you look at the car from a distance it will look like being shorter than 3 metres but in fact it will still be 3 metres long. If you move it to another parking lot it will retain its 3 metres length.

You should be transforming the item - rotating, scaling, translating it but the item itself will still have the original size and shape, so boundingRect() and shape() should return constant values unless the actual shape (outline) of the item changes (i.e. if you open the doors in your 3 metres long car).

Marnix
13th April 2010, 17:03
I use the mutiple objects for visualy measuring things on an underlying bitmap, so they realy schange shape. I solved with my problem with QTransform.map witch can rotate an QPainterPath.