开发者

Slowness loading large (2M) images into listWidget

I have a simple QlistWidget where I'm loading images in one call using this code:

ui.listWidgetImages->setIconSize(QSize(60, 60));
QStringList::const_iterator i = filenames.constBegin(); // QStringList that holds the images paths
while (i != filenames.constEnd()) {
  QString value = *i;
  QListWidgetItem *standardItemnew = new QListWidgetItem(value, ui.listWidgetImages);
  standardItemnew->setIcon(QIcon(value));    
  ++i;         
}

I guess the slowness is the result of scalling down the images to 开发者_StackOverflow中文版60/60 size but, is there any way to speed up the process?


The fastest soluton would be to pre-generate the thumbnails or use thumbnails already embedded in the image.

If that's not feasible your only option may be to us Qt's multithreading. There are two sides to this. To start with the entire task of populating the list could be hived off into a separate thread so that the application doesn't lock during the process. More ambitiously, if the users have multi-core systems you might consider loading and scaling each image in a separate thread.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜