PDA

View Full Version : Group/children positioning within Qt Graphics Framework



brcain
2nd July 2014, 01:23
Hello,

I'm having 3 (related) issues with grouping within the Qt Graphics Framework. These occur with either the QGraphicsItemGroup::addToGroup() or QGraphicsItem::setParentItem() grouping methods.

1) When you create a group within Qt, its initial position as reported by the pos() method is (0,0) independent of its child items' bounding rectangle. The group (when created) could be contained within the rectangle x=100, y=100, w=10, h=10 and it still has position of (0,0). This is not intuitive to the user; (0,0) isn't even within the bounding rectangle. The pos() should be the upper left (or center) of the bounding rectangle.

2) Rotating the group is relative to (0,0) -- not relative to the group's bounding rectangle.

3) There is no convenient way to get/set the actual scene-relative position and rotation for a child of a group. Moving the group has no effect on the position reported by the child pos() method. This is further complicated by the fact that QGraphicsItem uses two affine transformation systems: one for the setPos(), setRotation(), and setScale() methods and another for the setTransform() method. Coming from a gaming & simulation background, this is imho a completely non-standard way of handling transformations. This took my by surprise as most every other aspect of Qt employs industry common best practices.

Thanks,
Ben

anda_skoa
2nd July 2014, 09:09
Hmm, there doesn't seem to be any question in this posting, the closest thing seems to be the part about getting an item's position in scene coordinates.

I think that should be possible by mapping the item's pos() using the same item's mapToScene().

Cheers,
_

brcain
2nd July 2014, 18:06
Have you ever used software that provides the function above? My point was that it is non-standard behavior and I need help providing the features. I've restated the issues as questions below.

PowerPoint, Visio, et al all
1) provide to the user a group's position as relative to it's bounding rectangle (not zero)
2) rotate about the group bounding rectangle's center (not about center of scene)
3) provide the scene position of the child of the group (not independent of the group)

How are the original common features (mentioned above) normally provided to the user for Qt graphical applications such as PPT, Visio, etc? I'm developing an editor and need to implement said features. Why would Qt groups have a position of zero at creation that's independent of the bounding items? Why would rotating a Qt group rotate about the scene origin rather than the bounding region's center?

Additionally, how do you get the scene relative rotation for an element within a group that has been rotated and moved? I don't see a mapToScene() type API for rotation. I was able to compute it implementing my own 2D affine transformations, but it wasn't straight forward.

Finally, why would ungrouping a moved/rotated group of items produce the result of the grouped items in the position/rotation before they were grouped, moved, and rotated? It's not expected behavior. Is there something in Qt that readily provides this? Am I missing something?

Besides the issues above (not to be missed), but the mapToScene() position isn't reporting a correct value when the group has been moved and rotated and the group's children have been subsequently moved and rotated after grouping.
In the image below, the red graphic (numbered 1) is indicating a position from mapToScene of (-15, 25) rather than the correct value of (-10, 10).
10497

brcain
3rd July 2014, 17:50
anda_skoa (or wysota Master of all things Qt), can I get a more substantive response? ;)

It may be that Qt grouping is designed differently than PowerPoint, Visio, OpenOffice Impress, and every other tool I've used with grouping functionality.
Or, it may be that I'm missing something obvious because I'm too obtuse.

Nonetheless, would you provide a hint of direction and address the 3+ aforementioned issues?

Thanks much,
Ben

brcain
8th July 2014, 02:54
After wrestling with Qt's grouping implementation for about 4 days, I ended up refactoring the Qt graphics framework grouping functionality to provide the common features described above.
It's working great; a bonus ... it simplified implementation of the undo/redo operations.