[Qt-interest] Performance of Model and View
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Tue Jan 13 23:30:34 CET 2009
Or, don't use the generic model... Use a custom model with your own
::data method...
Handle the alignment role, and the data role, and have a custom
insertion routine...
Pretty straight forward, much cleaner code as well..
Scott
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Malyushytsky, Alex
> Sent: Tuesday, January 13, 2009 1:12 PM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Performance of Model and View
>
> You can disable update of the widget before changing model using
> setUpdatesEnabled() and enable it after you done.
> This should help with performance.
>
> http://doc.trolltech.com/4.4/qwidget.html#updatesEnabled-prop
>
> Alex
>
>
>
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of RZ
> Sent: Tuesday, January 13, 2009 1:00 PM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] Performance of Model and View
>
> Hi,
>
> I'm reading data from a file into the model - the (pseudo) code looks
> like this:
>
> model->insertRow(0);
> model->setData(model->index(0, 0), QString::number(_uint16));
> model->setData(model->index(0, 1), QString::number(_uint8));
> model->setData(model->index(0, 2), QString::number(_uint16));
> model->setData(model->index(0, 3), QString::number(_uint16));
> model->setData(model->index(0, 4), QString::number(_uint16));
> model->setData(model->index(0, 5), QString::number(_uint8));
> model->setData(model->index(0, 6), QString::number(_uint8));
> model->setData(model->index(0, 7), QString::number(_uint32));
> model->setData(model->index(0, 8), QString::number(_uint16));
> for (int i = 0; i < 9; ++i)
> {
> model->setData(model->index(0, i), Qt::AlignCenter,
> Qt::TextAlignmentRole);
> }
>
> model->setData(model->index(0, numColumns - 1),
> QString::fromStdString(decoded));
> model->item(0, 0)->setFlags(Qt::ItemIsSelectable);
> model->setData(model->index(0, 0), Qt::green, Qt::ForegroundRole);
> model->setData(model->index(0, 0), ttInfo, Qt::ToolTipRole);
> model->setData(model->index(0, 0), type, MsgTypeRole);
>
>
> With this code I have several problems. First of all it is slow (as it
> seems that the view gets updated after every "setData"), second it
> doesn't look "cool" (e.g. the for-loop to set the alignement), ...
>
> Is there a way I overlooked to improve this?
>
> Thanks,
>
> RZ
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
------------------------------------------------------------------------
------
> ---------------------
> Weidlinger Associates, Inc. made the following annotations.
>
> "This message and any attachments are solely for the intended
recipient and
> may contain confidential or privileged information. If you are not the
> intended recipient, any disclosure, copying, use, or distribution of
the
> information included in this message and any attachments is
prohibited. If you
> have received this communication in error, please notify us by reply
e-mail
> and immediately and permanently delete this message and any
attachments. Thank
> you."
>
> "Please consider our environment before printing this email."
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list