[PyQt] Connecting two QGraphicsItems

Marcell Mars marcell.mars at gmail.com
Mon Apr 6 14:30:07 BST 2009


On Mon, Apr 6, 2009 at 3:07 PM, Mads <kofoden at yahoo.com> wrote:
> I hope someone can help me witth this problem. It is probably straight forward
> I have a QGraphicsItem and a QGraphicsEllipseItem, when I add the QGraphicsItem to th
> graphicsview I want the QGraphicsEllipseItem to be added as well and be connected with
> the QGraphicsItem. So if you drag the QGraphicsItem around the QGraphicsEllipseItem
> will follow.

QGraphicsScene has method createItemGroup:

http://doc.trolltech.com/4.5/qgraphicsscene.html#createItemGroup

and by setFlag method you set QGraphicsItem.ItemIsMovable flag...

http://doc.trolltech.com/4.5/qgraphicsitem.html#setFlag




so your code could look like this:

myItemGroup = myScene.createItemGroup([myGraphicsItem, myEllipseItem])
myItemGroup.setFlag(QGraphicsItem.ItemIsMovable)

hope it helps..


More information about the PyQt mailing list