Search code examples
xmlqtpyqtqlistwidget

Getting the title of a QListWidget item in PyQt5


This is probably a really simple question, but in my program I'm adding entries from an XML to a QListWidget. When a QListWidget item is selected, it triggers a change in a QLabel. I want the QLabel to have the same text as the QListWidget item. How would this be done? Important Code: http://pastebin.com/90qDkdHe (permanent)


Solution

  • You can use QListWidget.currentItem to retrieve the currently selected item and text returns it's text. So it could be like :

    self.listWidget.itemSelectionChanged.connect(self.changeHackModifier)
    
    def changeHackModifier(self):
        self.memtitle.setText(self.listWidget.currentItem().text())