How can I improving performance when I use QListView with large numbers of items
-
@sierdzio Yep,it works. I think it's just one more overloaded function (columnCount) than QAbstractListModel, rigth?
By the way,How can i optimize the date() method. ```
QVariant CLogSqlModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant();
if(role == Qt::DisplayRole)
{
return m_LogList.at(index.row()).LogTime.toString("yyyy.MM.dd hh:mm") + m_LogList.at(index.row()).LogDesp;
}
else if (role == Qt::BackgroundRole)
{
if(index.row()%2 == 0)
return QColor(Qt::darkGray);
else
return QVariant();
}
else
return QVariant();
} -
Hm ok that looks simple enough. Only small optimization I'd suggest is for DisplayRole:
const auto &item = m_LogList.at(index.row()); return item.LogTime.toString("yyyy.MM.dd hh:mm") + item.LogDesp;
to avoid traversing the list twice. But I don't know any implementation details here, so it is mostly a guess.
Does m_LogList perform any heavy calculations, or complex data reads (SQL or something), or is it just a static list?
-
@Mihan
you can combine qml and Widgets yes.The classes QQuickWidget and QQuickView are specifically made for that purpose.
Atm, to my knowledge, there's no official way to create embeded QWidgets into QML.
So only QML components in QWidgets
-
@J.Hilk said in How can I improving performance when I use QListView with large numbers of items:
Atm, to my knowledge, there's no official way to create embeded QWidgets into QML.
There's KDAB's DeclarativeWidgets which might be of some help.
-
@SGaist Hi SGaist
I found the Listview showed nothing few second if the layoutmode is batched.So I want to add a loading gif to make it .......Uh, you know that? Like the reflash of web and so on. But I can't find some signals or event about update, just it has a updatelater event when i used eventfiler to show all events. Could you give me a hand?
Thank you so much! -
How many items are you loading ?
-
Depending on what you are going to do with these items, you will likely need to implement things like windowing to avoid having uselessly too many items in memory.