[Qt-interest] signal itemClicked and signal itemChanged of QTreeWidgetItem

yanqzhi at gmail.com yanqzhi at gmail.com
Wed Mar 3 04:19:14 CET 2010


It is a good idea! But I can't hnow whether the clicded item's state have changed in the slot corresponding the signal ItemClicked.

My taget is below:
If a QTreeWidgetItem's state is checked or unchecked, its children checkStates will change as the item(parameter).
And also if its siblings checkStates are same as the state of the item(parameter),its parent's checkState will change as the item(parameter);
If its siblings states are not same as the state of the item, the parent's state will be set as Qt::PartiallyChecked;

I do that just as below:
When the signal itemClicked is emitted,the corresponding slot itemSelect will set mSelectedItem = item (parameter).

When the signal itemChanged is emitted, the corresponding slot updateCheckState will set the children states same as the checkState of item(parameter),
and set its parent's checkState according to the item's checkState and its siblings checkStates; if the item's(parameter) parent or child == mSelectedItem the slot updateCheckState will end;

But I don't hnow itemClicked and itemChanged which will be emitted firstly.When I debug the program I found that itemChanged always have been emitted firstly.
So I can't achieve my goal.

Any good idea?

Thanks a lot!

Sincerely yours, 
Yan
yanqzhi at gmail.com 
2010-03-03 

======= 2010-03-02 19:33, your message: Re: [Qt-interest] signal itemClicked and signal itemChanged of QTreeWidgetItem======= 

On Tuesday 02 March 2010 10:47:34 yanqzhi at gmail.com wrote: 
> CProductTreeWidget::CProductTreeWidget(QWidget *parent) 
> 
> : QTreeWidget(parent) 
> 
> { 
> ui.setupUi(this); 
> mSelectedItem = NULL; 
> connect( this, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), 
> this, SLOT( itemSelect( QTreeWidgetItem*, int ) ) ); 
> connect( this, SIGNAL( itemChanged( QTreeWidgetItem*, int ) ), 
> this, SLOT( updateCheckState( QTreeWidgetItem*, int ) ) ); 
> } 
> 
> When I click the checkbox of a QTreeWidgetItem of the CProductTreeWidget, I 
> found that the slot updateCheckState will be excuted firstly and the slot 
> itemSelect will be excuted secondly. But I want that the slot ItemSelect 
> be excuted firstly. 
> 
> How can I do? 
> 
> Thanks a lot! 
> 
> Sincerely yours, 
> Yan 
> 
> yanqzhi at gmail.com 
> 2010-03-02 
The order of the slots being called is random. 
As it is never certain which slot will called first you have to maybe use a 
different approach: 
only connect only the slot itemSelect 
>From inside the itenSelect slot do whatever you need to do. You may even 
define an own SIGNAL, connect it to the updateCheckState() and emit that 
SIGNAL from inside the itemSelect slot. 

Hope this helps 

Eckhard 

_______________________________________________ 
Qt-interest mailing list 
Qt-interest at trolltech.com 
http://lists.trolltech.com/mailman/listinfo/qt-interest 
. 


= = = = = = = = = = = = = = = = = = = = 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100303/5e1a24de/attachment.html 


More information about the Qt-interest-old mailing list