Issue
I was looking for a method to get a text/ name of the clicked element on a listWidget.
This was my approach looks like:
# call lamp clicked event
self.listWidget_lamps.itemClicked.connect(self.lamp_clicked)
# call group clicked event
def lamp_clicked(self):
self.lamp_on = True
self.group_on = False
lamp = Lamp(self.item.text())
print("lamp" + self.item.text() + "got clicked")
but it always crashes and gives me this error:
lamp = Lamp(self.item.text())
AttributeError: 'MainWindow' object has no attribute 'item'
Could someone please tell me what Im doing wrong?
Solution
The signature of your slot lamp_clicked
is wrong. Take a look at QListWidget::itemClicked and note that the signal has one parameter but your slot takes no parameter.
def lamp_clicked(self, clickedItem):
self.lamp_on = True
self.group_on = False
lamp = Lamp(clickedItem.text())
print("lamp" + clickedItem.text() + "got clicked")
should do the trick.
Answered By - SebDieBln
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.