[Qt-interest] QListWidget increasingly slow

R. Reucher rene.reucher at batcom-it.net
Tue Nov 10 20:24:44 CET 2009


On Tue, 10 Nov 2009 11:43:41 -0700, Bob Hood wrote:
> I'm looking for some advice here.  I'm using a QListWidget as a log
> window, and for short output, it's fine.  However, when I get into
> thousands of lines, it slowly grinds my application to halt as lines are
> added to it.
> 
> I know the culprit, though.  I've narrowed it down to the
> setCurrentRow() method:
> 
>     log_list->addItem(msg);
>     log_list->setCurrentRow(log_list->count() - 1);
> 
> I am using setCurrentRow() to keep the most recent item in the list
> visible to the user as entries are added.  If I remove this call,
> everything runs comparatively smoothly -- but entries being added are
> not visible unless the user manually drags the scroll bar down.  I've
> also tried using setCurrentItem() to keep things visible, with the same
> asymptotic results.
> 
> Is there a more efficient way to keep most-recent entries visible using
> QListWidget?  I'm using QListWidget so I can colorize entries, and add
> icons to the lines, so if there's a better Qt widget for displaying
> thousands of lines of text that would give me the same features
> (colorization and icons), then I'd be happy to try it.
Does using scrollToItem() instead of setCurrentRow() change the situation?

I'm using QTextBrowser's for logs, and they act quite fast.

For lists of thousands of items, I usually use QTreeWidget's, and I don't 
experience those issues. As they are both derived from QAbstractItemView, 
they should be fairly similar... but I haven't used QListWidget's for 
this purpose (very large lists) yet, so I'm not absolutely sure. 

Also, if you can combine a set of item insertions that need to be done in 
a short time frame, you could/should temporarily disable updates to the 
QListWidget until after the scroll operation (to the last item).

HTH, René
-- 
René Reucher
rene.reucher at batcom-it.net
http://www.batcom-it.net/

Please, won't somebody tell me what diddie-wa-diddie means?



More information about the Qt-interest-old mailing list