Hi all,<br><br>I want to gather some of my QGraphicsItems in a parent node to be able to translate and rotate the whole set easily. Additionally I want to be able to select on of the items inside the set. So here is one of the approaches I've tried - it uses QGraphicsItemGroup (I made it as short as possible):
<br><br>import sys<br>from PyQt4 import QtGui, QtCore<br><br>class MyItem(QtGui.QGraphicsItem):<br>&nbsp;&nbsp;&nbsp; def __init__(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QtGui.QGraphicsItem.__init__(self)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def boundingRect(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 
QtCore.QRectF(0,0,10,10)<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def paint(self, painter, option, widget):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pen = QtGui.QPen(QtCore.Qt.SolidLine)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.isSelected():<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pen.setColor(QtGui.QColor(255, 0, 0))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
painter.setPen(pen)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; painter.drawEllipse(0,0,10,10)<br><br>class MyView(QtGui.QGraphicsView):<br>&nbsp;&nbsp;&nbsp; def __init__(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QtGui.QGraphicsView.__init__(self)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.scene = QtGui.QGraphicsScene
(self)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.scene.setSceneRect(-100, -100, 200, 200)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.group = QtGui.QGraphicsItemGroup()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = MyItem()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i.setPos(-10,0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.group.addToGroup(i)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.group.addToGroup
(MyItem())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.scene.addItem(self.group)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.setScene(self.scene)<br><br>app = QtGui.QApplication(sys.argv)<br>view = MyView()<br>view.show()<br>sys.exit(app.exec_())<br><br>The problem is that QGraphicsItemGroup does not allow me to select items which are inside the set. I've tried to set the 
QGraphicsItem.ItemIsSelectable flag for MyItem and QGraphicsItemGroup but it does not help. Interesting thing is that when you change QGraphicsItemGroup to QGraphicsEllipseItem (and probably to other Item types as well) and use setParentItem() to attach the items to it you will be able to select the items. What is the logic behind it? I've also tried to use setParentItem() in combination with QGraphicsItemGroup(). Am I missing something? I don't want to subclass QGraphicsItem to build my own group item or to use Ellipse to gather all the items :] For me it looks like the inconsistency between QGraphicsItemGroup and other Items which inherit from QGraphicsItem - but I hope I'm wrong.
<br><br>Another observation is that if you remove QGraphicsItemGroup from the scene the items within the group are not deleted (I mean underlying C/C++ objects). This is completely different behavior than this discussed recently in the mailing list. Using 
e.g. QGraphicsEllipseItem along with setParentItem() method you can easily destroy all underlying C/C++ objects by removing the parent node. QGraphicsItemGroup behaves differently, or maybe I'm missing something once again?
<br><br>thanks for your patience and help<br>best regards,<br>Krystian Samp<br>