2

I was able to add custom QListWidgetItem in QListWidget using the following code -

for item in dl_list:            
        widget = QtWidgets.QWidget()
        card = Ui_DownloadCard()
        card.setupUi(widget)
        card.set_filename(item["title"])
        card.set_progress_bar(item["progress"])
        card.set_progress_text(item["progress"]/item["size"])
        card.set_speed(item["speed"])

        listItem = QtWidgets.QListWidgetItem(self.download_list)
        listItem.setSizeHint(widget.sizeHint())

        self.myListWidget.addItem(listItem)
        self.myListWidget.setItemWidget(listItem, widget)

Now I wish to update each item with new speed & progress. I tried the following code -

self.myListWidget.item(0).set_speed("300 KB/s")

But it gives error saying

AttributeError: 'QListWidgetItem' object has no attribute 'set_speed'

So what is the correct way to update the item?

Shivendra
  • 556
  • 3
  • 15
  • How are we supposed to know that when you don't show us what `download_list` is? Consider [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Matho Jun 18 '17 at 08:59
  • Why do you say you are using a `custom QListWidgetItem` if the item you use is the one that comes by default, ie QListWidgetItem? – eyllanesc Jun 19 '17 at 07:48

2 Answers2

0
listItem = QtWidgets.QListWidgetItem(self.download_list)

you need use your custom item instead:

listItem = YourCustomListWidgetItem(self.download_list)
MarStarck
  • 433
  • 7
  • 14
0

From specs: http://pyqt.sourceforge.net/Docs/PyQt4/qlistwidget.html#setItemWidget

QListWidget.setItemWidget

This function should only be used to display static content in the place of a list widget item. If you want to display custom dynamic content or implement a custom editor widget, use QListView and subclass QItemDelegate instead.

So if you want to work with dynamic components it's necessary to use QListView and subclass QItemDelegate instead.

Boris Davidov
  • 294
  • 2
  • 6