PDA

View Full Version : Appliation specific data to the QGraphicsScene items



ravi.xolve
3rd May 2011, 13:12
I am using PyQt.

I am adding QPolygonF to it and adding my own data to each class as:


polygon.data = ownData

Python allows dynamic binding so I can do it. I later want to query for items that lie within the given rectangle using items() method and check the items in the returned list for "data" I get AttributeError. Does addPolygon() only draws and not stores the items?

qlands
3rd May 2011, 13:43
data() returns a pointer to the data stored in the vector. The pointer can be used to access and modify the items in the vector. This is the polygon data. If you want to store custom data at item level use:

QVariant QGraphicsItem::data ( int key )

ravi.xolve
4th May 2011, 05:12
In fact I found the solution. One cannot use the QPolygonF, but need to use QGraphicsPolygonItem which provides the data() method.