How can I delete a QCanvasItem in PyQt?

Baki Kose baba at localhost.localdomain
Sat Aug 17 16:11:33 EDT 2002


Hi All,

The following code is taken from canvas/canvas.cpp in the Qt examples 
directory. I am trying to implement this in PyQt, however since
PyQt doesn't implement QCanvasItemList I am using Python list to
hold the current QCanvasItem(s).

void FigureEditor::clear()
{
    QCanvasItemList list = canvas()->allItems();
    QCanvasItemList::Iterator it = list.begin();
    for (; it != list.end(); ++it) {
        if ( *it )
            delete *it;
    }
}

Here is how I (attempted) to re-implement this function
in PyQt, but it doesn't delete the items. Can anyone
tell me how I can fix this?

    def clear(self):
        ilist = self.canvas.allItems()
        for each_item in ilist:
            if each_item:
                del each_item

Thanks
sadi




More information about the Python-list mailing list