[Qt-interest] QTreeWidget and checkable items

Lorenzo Berni duplo at develer.com
Fri Feb 20 15:00:24 CET 2009


> Il giorno 20/feb/09, alle ore 13:10, Andreas Pakulat ha scritto:
>
>> On 20.02.09 12:41:24, Lorenzo Berni wrote:
>>> I'm working on a QTreeWidget. The items of this QTreeWidget are
>>> checkable and I want to be notified when one of them is checked (or
>>> unchecked). In the documentation I can't find any signal for this
>>> purpose so I decide to implement one using the itemPressed signal  
>>> and
>>> checking the state of the item passed by this. But when i click on  
>>> an
>>> item's checkbox the item passed by the signal has the previous state
>>> instead of the current one, probably because the state is changed
>>> after the signal is emitted. In fact clicking on the item (not on  
>>> the
>>> checkbox) the signal is emitted, and in this case the state is the
>>> right one.
>>>
>>> Anyone has an idea to resolve this problem?
>>
>> - you probably want to use itemClicked(), that will be emitted when  
>> the
>> click is complete (i.e. press+release have happened) and hence the  
>> state
>> will be correct
>> - you could use the itemChanged() signal instead, which is fired  
>> when the
>> data of the model changes (and changing the checkbox state is a data
>> change)
>> - you could consider replacing the treewidget with a custom model +
>> standard treeview and then have your checkableChanged() signal  
>> emitted
>> directly from your setData() method
>>
>> Andreas

Thanks a lot, itemChanged is exactly what I'm looking for... I  
believed that the itemChanged only lookd for changes in the label.
Thanks really.

--
Lorenzo Berni
Develer S.r.l.
http://www.develer.com




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090220/b8423bba/attachment.html 


More information about the Qt-interest-old mailing list