Search code examples
pythonqtpyqt4qlistwidget

How to move content from QListWidget to a QStringList with PyQt4?


I have a dialog in which a user selects the files that needs, it adds (via QPushButton) in a QListWidget, my problem it's that I need to recover all the files from the QListWidget in a QStringList.

I tried like this, but something is wrong:

        self.file = QtCore.QStringList()
        archivos = self.file

        cuenta = self.ventana.listWidget.count()
        for index in range(cuenta):
            archivos.append(self.ventana.listWidget.item(index))

Solution

  • I think you're missing .text() after the item:

        self.file = QtCore.QStringList()
        archivos = self.file
    
        cuenta = self.ventana.listWidget.count()
        for index in range(cuenta):
            archivos.append(self.ventana.listWidget.item(index).text())