Ejaz
Ejaz

Reputation: 1632

How to display a QListWidget Item

I am running the below code:

    self.myList = QListWidget()
    for i in range(3):
        self.Item = QListWidgetItem()
        self.name = 'A'+'%04d'% i
        self.Item.setText(self.name)
        self.myList.addItem(self.Item)
    print self.myList.selectedItems()

it prints an empty list:

[]

Please suggest where I am missing.

Upvotes: 0

Views: 674

Answers (1)

Arenim
Arenim

Reputation: 4247

According to QT docs (i've used c++ ones, but it's ok for python bridge as well),

QList<QListWidgetItem *> QListWidget::selectedItems () const
Returns a list of all selected items in the list widget.

This means, that print self.myList.selectedItems() will output all the list of items user was selected, not all the items are in widget.

You can try to use count() to get number of items and item(number) to get one.

Upvotes: 1

Related Questions