How can I get the texts of all the widgets in a QListWidget
as a QList<QString>
?
I can get the list of widget items like this:
QList<QListWidgetItem *> items =
ui->l开发者_如何学PythonistWidget->findItems(QString("*"), Qt::MatchWrap | Qt::MatchWildcard);
But that's not exactly what I want, I'd like the list of the widget text()
properties.
There is no built-in function for that, you'll need to do it manually.
QList<QString> texts;
foreach(QListWidgetItem *item, items)
texts.append(item->text());
Or something like that.
int c = ui->listWidget->count();
for (int i = 0; i < c ; ++i){
QString s = QString::number(i);
QModelIndex *model_index = new QModelIndex(ui->listWidget->model()->index(i,0) ); //0th column since we have one cloumn in listwidget
QString q= model_index->data(Qt::DisplayRole).toString();
qDebug()<<q;
}
精彩评论