[PyKDE] QCanvas items: self created ClassItem appears as QCanvasPolygon or similar

Karl myonlyb at vollbio.de
Sun May 30 13:45:01 BST 2004


Approx. 2 years ago, me and some collegues created a program in university 
using Python and Qt 2. It worked then, now I want to try to port it to Qt 3 
and then finish/improve it.

I found some very strange behaviour and would ask, whether anyone knows 
what is wrong?

Problem description:
I have a Canvas, on this Canvas, I put some Items.
To do this, I created a class that is called "ClassItem" (the program is a 
case tool, ClassItem represents a class) that inherits QCanvasRectangle and 
a Class called Item that has some logical stuff about my items.

This is a short excerpt from the constructor of ClassItem:

 >class ClassItem (QCanvasRectangle, Item):
 >	def __init__(self, guiManager, clsId):
 >		Item.__init__(self, guiManager, CLASSTYPE, clsId, 1)
 >		QCanvasRectangle.__init__(self, self.canvas)

Now, when I create my ClassItems, they should be added to the Canvas just 
when the constructor calls QCanvasRectangle.__init__(...), right?
But somehow, not all these Items are added to the canvas as *ClassItem*, 
but e.g. as QCanvasPolygon.

Excerpt from my debug output:

 >.adding class
 >..class created: <ClassItem.ClassItem object at 0x00912FC0>
 >..items now on Canvas: [<ClassItem.ClassItem object at 0x00912FC0>]
 >.adding class
 >..class created: <ClassItem.ClassItem object at 0x00917030>
 >..items now on Canvas: [<ClassItem.ClassItem object at 0x00917030>, 
<ClassItem.ClassItem object at 0x00912FC0>]
 >.adding class
 >..class created: <ClassItem.ClassItem object at 0x009170C0>
 >..items now on Canvas: [<ClassItem.ClassItem object at 0x00917030>, 
<__main__.qtcanvas.QCanvasPolygon object at 0x009170F0>, 
<ClassItem.ClassItem object at 0x00912FC0>]

As you can see, the third ClassItem is in fact created as ClassItem, but it 
is added to the Canvas as QCanvasPolygon.
I don't see any difference between these items and don't understand, why 
the program behaves this way...
In the following, the QCanvas.collisions()-method results this 
QCanvasPolygon, on which I cannot call the methods, that are specific for 
ClassItem, therefore, there is no difference for me, if this ClassItem is 
present or not, I cannot work with it...

Can anyone help, please?

  Tnx in advance

More information about the PyQt mailing list