[英]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. 我有一个对话框,用户可以在其中选择所需的文件,并在QListWidget中添加(通过QPushButton),我的问题是我需要从QStringList中的QListWidget中恢复所有文件。
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))
I think you're missing .text()
after the item: 我认为您在该项目之后缺少.text()
:
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())
As I understood, you need to add the selected item text value to a QStringList. 据我了解,您需要将选定的项目文本值添加到QStringList。 Here's how to do it. 这是操作方法。
QStringList *mList = new QStringList();
QString currItem = ui->listWidget->currentItem()->text();
mList->append(currItem);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.