[Qt-interest] QTreeWidget and checkable items
Andreas Pakulat
apaku at gmx.de
Fri Feb 20 13:10:56 CET 2009
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
--
You will wish you hadn't.
More information about the Qt-interest-old
mailing list