burntchowmein
burntchowmein

Reputation: 469

How to trigger a function after clicking on a list item in a QListWidget? PyQt5

I want to know how to trigger the function "self.runEverything" when a specific item in a list widget is selected. I tried this but nothing is happening because I am not entering the if-statement.

if(self.listwidget.item(0).isSelected()):
    self.runEverything(filepath)

Upvotes: 1

Views: 1232

Answers (1)

icwebndev
icwebndev

Reputation: 413

You may want to check QListWidget currentRowChanged signal.

So, depending on the thing you want:

# example call
# QListWidget::currentRowChanged() emits an int value.
self.listwidget.currentRowChanged.connect(self.slotOrLambdaFunction)

def slotOrLambdaFunction(self, idx : int):
   if idx == 0:
     self.runEverything(filePath)

And then trigger stuff you need from the currently selected row in the widget.

You can also use QListWidget::itemClicked(QListWidgetItem item).

Upvotes: 1

Related Questions