[PyQt] can't correctly delete the icons of a QListView

alteo_gange romanocaldoni at free.fr
Thu Dec 4 21:43:56 GMT 2008


Hi,

I can't delete all the icons that i have selected in a QListView. Only half 
are deleted and not always those that i have selected. The row indexs change 
when i start to delete them. I had tried to lock the row index with the 
beginRemoveRows() fonction but that not works.


def __init__(self):
    ...
    self.model=QStandardItemModel()
    self.list = QListView()
    self.list.setViewMode(QListView.IconMode)
    self.list.setSelectionMode(QAbstractItemView.ExtendedSelection)
    self.list.setModel(self.model)
    ...
    delAction = QAction(self)
    delAction.setShortcut(QKeySequence.Delete)
    self.connect(delAction, SIGNAL('triggered()'), self.deleteIndex)
    self.addAction(delAction)
...
def deleteIndex(self):
    "Delete all the indexs selected in the QlistView"
    for index in self.list.selectedIndexes():
        self.model.beginRemoveRows(index, index.row(), index.row())
        self.model.removeRow(index.row())
    self.model.endRemoveRows()
    ...

def addItem(self):
    ...
       self.model.appendRow(item)
...


---
Romain



More information about the PyQt mailing list