Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Combining QGraphicsSvgItem with QGraphicsLayoutItem
Hi, I'm working on a small project (inspired by "this(Layoutitem)":http://qt.gitorious.org/qt/qt/blobs/master/examples/graphicsview/basicgraphicslayouts/layoutitem.cpp) where I am trying to combine the powers of QGraphicsSvgItem and QGraphicsLayoutItem.
You can find the project "here (QGraphicsSvgLayoutItem)":http://gitorious.org/qgraphicssvglayoutitem/qgraphicssvglayoutitem/trees/master with a test case, it's ready to compile.
The problems I currently have are:
- Rotation behaves funny -- the item is rotated, but when you resize the window it behaves in a weird way (it's scaled in wrong directions)
- When I set a parent item to my item, it does not seem to be displayed at all.
I would appreciate all hints and help :)
jorj last edited by
does the layout work if you dont use an svg item? try just an ellipse item or something else.
Hi Jorj, thanks for input! I have subclassed QGraphicsLayoutItem together with QGraphicsRectItem (because I can not simply put the QGraphicsItem into QGraphicsLayout) and even thought the code is now much shorter and straightforward, the same problem is still present. But it should be easier to hunt down the problem now with the simple rect item.
"Here ((Compilable testcase)":http://filebeam.com/620ef986954780b93a675fee1a865571 (or "here (Compilable testcase)":http://palmik.net/files/QGraphicsRectLayoutItem_pack.rar) is the whole compilable source with testcase and "here on codepad is(Codepad sample)":http://codepad.org/VqYnWtoY just the QGraphicsRectLayoutItem implementation.
Ok, when I was having a batch I realized that the reason for that weir behavior if fairly simple... it's because it always draws the painting of size of the bounding rect, which forks fine (when the rotation() % 180 == 0) but otherwise it does not work, since the bounding rect in my implementation is the same for all items in the layout.
Now to the solution -- there are at least two ways I can think of to solve this problem
Shrink the item when rotated (possibly by tinkering with the paint() reimplemantion) so that the geometry() would be same for all the cells of layout but will not overlap other cells.
Expand the bounding rect when rotated (possibly by tinkering with geometry() reimplementation) so that the item will be of the same size as if it would be unrotated but will not overlap other cells.
I will probably implement both at some point... Now I just have to figure out the math to calculate the sizes properly. :)