0

I have a qlistwidget in which most items are hidden.

The amount of items shown in the widget are determined by the users input.

I would like to be able to take the shown items in the qlistwidget and turn them into a list.

Sometimes there will be 3/4 items shown.

How can I make a list of the 3 items shown in the qlistwidget?

Problem illustration:

Qlistwidget window: 
------------------
| item 1         |
| item 2         |
| item 3(hidden) |
| item 4         |
|                |
|                |
|                |
------------------

pseudocode:

list_of_visible_items = []

for item in Qlistwidget window:
    if item not hidden:
        list_of_visible_items.append(item)
    
print(list_of_visible_items)

[item 1, item 2, item 4]
  • Your question is unclear, could you explain me better in addition to providing a [mre] – eyllanesc Sep 08 '21 at 01:13
  • I have rewritten my original post. I hope that is more understandable. I cannot find an example so I can't produce an example. I know what I want to do, but not how to do it. I can provide images of my current window, but I don't have enough rep. –  Sep 08 '21 at 01:21

1 Answers1

0

If you want to get the texts of the visible items then you just have to iterate over the items, check their visibility and get the text:

results = []
for row in range(listwidget.count()):
    item = listwidget.item(row)
    if not item.isHidden():
        text = item.text()
        results.append(text)
print(results)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241