tags:

views:

82

answers:

1

I have a fairly simple PyQt application in which I'm placing instances of a QGraphicsWidget in a QGraphicsGridLayout and want to connect the widgets with lines drawn with a QGraphicsPath. Unfortunately, no matter what I try, I always get (0, 0) back as the position for both the start and end widgets.

I'm constructing the graph with a recursive function that adds widgets to the scene and layout. Once the recursive function is complete, the layout is added to a new widget, which is added to the scene to show everything. The edges are added to the scene as widgets are created.

How do I get a non-zero position of any of the widgets in the grid layout?

Update: I forgot to mention that I've tried both pos() and scenePos() on the widgets in the grid layout. Both always return (0, 0) as the position for every widget in the grid.

A: 

If you use the QGraphicsItem::pos(), it gives you the position of the item in the parent coordinates. When using QGraphicsLayout, the parent is probably the cell containing the object thus the coordinate is equal to zero.

Since you want to connect widgets with path, you will need scene coordinate to define the control points: use QGraphicsItem::scenePos() to obtain the position of your QGraphicsWidget in the scene.

Lohrun
Ah - sorry, I forgot to mention it above. I've tried both pos() and scenePos(). Both return a (0, 0) point for all the widgets I've placed in the grid layout.
Chris Phillips