PDA

View Full Version : Merging and splitting of QGraphicsRectItem



mvbhavsar
18th April 2017, 14:32
Hi,

I want to develop a functionality where there is push button which will add QGraphicsRectItem on QGraphicsScene. Once there are multiple QGraphicsRectItem on scene, user will select more than one and there will be another button which will merge these selected QGraphicsRectItems into single QGraphicsRectItem having childrenBoundingRect() as merged entities bounding rect. And when I will select merged item on scene it will show me as single item since this merged item will become parent for other children.

Can anybody help me in merging idea?


Manish

wysota
18th April 2017, 14:49
If the merge is an unreversible operation then the easiest solution is to replace several rect items with a single new rect item with a bounding rect and position based on those of its source items.

If the merge is to be reversible though, it might be easiest to use QGraphicsItemGroup or implement a similar custom solution.

mvbhavsar
18th April 2017, 14:58
Thanks for quick reply.
Replacing was also my though but in that case I need to remove selected, get posting of top-left removed item and the create new item there. right?

wysota
18th April 2017, 16:10
Something like that, yes.