PyQt4 - Remove Item Widget from QListWidget

后端 未结 3 1593
鱼传尺愫
鱼传尺愫 2021-01-12 13:05

I have a QListWidget and I need to remove some items.

From what I\'ve researched, this is a generally unpleasant thing to do.

I\'ve read a tonne of solut

相关标签:
3条回答
  • 2021-01-12 13:23

    takeItem() should work:

    for SelectedItem in self.ListDialog.ContentList.selectedItems():
        self.ListDialog.ContentList.takeItem(self.ListDialog.ContentList.row(SelectedItem))
    
    0 讨论(0)
  • 2021-01-12 13:28

    That's weird there isn't some direct way to delete items from QListWidget ... Try this:

    listWidget = self.ListDialog.ContentList
    model = listWidget.model()
    for selectedItem in listWidget.selectedItems():
        qIndex = listWidget.indexFromItem(selectedItem)
        print 'removing : %s' %model.data(qIndex).toString()
        model.removeRow(qIndex.row())
    
    0 讨论(0)
  • 2021-01-12 13:47

    Deleting an Item from ListWidget:

    item = self.listWidget.takeItem(self.listWidget.currentRow())
    item = None
    
    0 讨论(0)
提交回复
热议问题