[PyKDE] PyQT 4.x Display Roles

Matt Chambers chambers at imageworks.com
Thu Oct 12 03:46:45 BST 2006


Andreas Pakulat wrote:
> On 11.10.06 13:10:34, Matt Chambers wrote:
>   
>> Andreas Pakulat wrote:
>>     
>>> On 10.10.06 21:19:59, M.Chambers wrote:
>>>  
>>>       
>>>> How can I disable some that I'm not using?  Seems like a waste to call
>>>> data() that many times.  I'm using the model view stuff and its very
>>>> slow compared to Qt3.
>>>>    
>>>>         
>>> You can't or at least you can't with the built-in Q*Views. You'd have to
>>> write your own view class that only asks for the roles you need.
>>>
>>> Also for speeding things up, try to check the role parameter as one of
>>> the first things and return an empty QVariant() if it is uninteresting.
>>>
>>> If that's still to slow get a profiling tool and check where the time is
>>> really spend.
>>>
>>> Andreas
>>>
>>>  
>>>       
>> I ended up making a single QVariant and return that over and over again, helped 
>> to speed it up:
>>     
>
> I'm curious as to what you had before? That's what you posted is exactly
> what I would've done in the first place...
>
> Andreas
>
>   

Many examples show data() actually doing stuff like

if role != QtCore.Qt.DisplayRole:
    return QtCore.QVariant()

I was able to eek out quite a bit more speed by creating a global 
instance of QVariant and returning the same one over and over again, 
instead of
creating a new object every time data is called, which can be hundreds 
of times in just a few seconds.

so I do:
if role != QtCore.Qt.DisplayRole:
    return EMPTY_QVARIANT


My cpu fan still comes on if I use the scroll bar but its not as bad.

-- 
*Matt Chambers <chambers at imageworks.com>*
*Sony Pictures Imageworks*

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20061012/334decc4/attachment.html


More information about the PyQt mailing list