Hi everyone,
I have a huge list of strings (up to 5.000) in a QStringList that I want to display in a custom way (not only as a simple list of strings).
Therefore I created a QWidget in designer in the way how each of my list entries should be displayed.
The custom QWidget:
Screen Shot 2016-11-07 at 15.25.49.png
In my mainview I want to have a QListWidget or QListView that uses my QStringList as data model (may I have to switch to QStringListModel) but display each line as one of the above QWidgets.
And if the data of the model (QStringList/Model) changes the QListWidget/View should update automatically.
My desired result (with display button mouseover):
Screen Shot 2016-11-07 at 16.04.57.png
Don't worry there will be a search bar too.
I know how to make a (simple) QListView that uses and reacts on changes of a model.
I also know how to get the custom QWidget into a QListWidget.
But I have no idea on how to connect these two things and have a view that is filled by and reacts on a models data and displays the data in custom widgets.
This is how I currently update my view.
It deletes all current entries fetches the list again and fills in everything again, but I think there has to be a way to make that easier/better.
void updateView() {
ui->listWidget->clear();
m_dataList->clear(); // QStringList
// fill the given QStringList with data
getData(m_dataList);
foreach
(const QString &itemInList, m_dataList
) { ListEntry *entry = new ListEntry(itemInList, ui->listWidget);
item->setSizeHint(size);
listWidget->setItemWidget(item, entry);
connect(entry, &ListEntry::delete,
this, &MainWindow::onDeleteClicked);
}
}
void updateView() {
ui->listWidget->clear();
m_dataList->clear(); // QStringList
// fill the given QStringList with data
getData(m_dataList);
foreach (const QString &itemInList, m_dataList) {
ListEntry *entry = new ListEntry(itemInList, ui->listWidget);
QSize size(60, 60);
QListWidgetItem *item = new QListWidgetItem(listWidget);
item->setSizeHint(size);
listWidget->setItemWidget(item, entry);
connect(entry, &ListEntry::delete,
this, &MainWindow::onDeleteClicked);
}
}
To copy to clipboard, switch view to plain text mode
Maybe there is just a little piece to solve it that I'm currently totally not aware of.
Kind regards for everyone to help out.
Bookmarks