Group multiple QGraphicsItems into single entity to move/select



  • I have an circuit drawn with few QGraphicsLineItems and QGraphicsImageItems. Now I wish to select all these items together such that I should be able to move all items together to a new position with items remain intact together. Now that each lineitem and imageitem can be moved separately, I wish to do it as one single entity. can you please guide me how to proceed about it? Should I store all the coordinates of all items and start re-drawing from the new position? or do we have an elegant way to make the whole circuit select/move ?



  • Were you looking for [[doc:QGraphicsItemGroup]] perhaps?



  • Thanks Andre, but selection of one item in the group will automatically select the group as well right? My scenario is I have electric circuit, now user does selection of all wires and elements (lineitems and imageitems) and click either delete/rotate/copy/cut/paste and this should perform action on whole selected set. On other hand, user can choose only one item(lineitem or imageitem) and perform the above actions as well. So, how can I achieve both?



  • Well, you could build up a group dynamically. If you add an element to your selection, add it to the group. Then perform the operations on the whole group. At least that is how I would try to do it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.