PDA

View Full Version : Checked item in QTreeWidget?



vishal.chauhan
26th December 2007, 07:43
Hi All,

I am working on qt 4.2.2 on my MAC Tiger.
I have a project in which I am change the state of a QTreeWidgetItem when an item is checked or unchecked.

This is working fine in qt 4.2.2 but when i tried this code on qt 4.3.2 then more often the item is not get checked or unchecked when i click on the item.

I want to ask whether it is due to Qt 4.3.2 or i have to do something different to do it.

Thanks.

wysota
26th December 2007, 10:34
Can we see the code?

vishal.chauhan
26th December 2007, 11:58
Hi,

I m having a QTreeWidget and inserting item in the treeWidget as follows.



QTreeWidgetItem *item = new QTreeWidgetItem(MyTreeWidget);
item->setText(0,"My Text");
item->setIcon(0,icon);
item->setText(1,"--");
item->setCheckState(0,Qt::Unchecked);



and when I click on the item in the treeWidget on Qt 4.2.2 it is checked immediately but when i am using this code in Qt 4.3.2 then the item is not checked immediately (often) and sometime it is not even checked and also giving the look of disable treeWidget.

wysota
26th December 2007, 12:00
Try adding:

item->setFlags(item->flags()|Qt::ItemIsUserCheckable);

vishal.chauhan
26th December 2007, 12:11
Thanks for reply.

but it doesnot making any difference.
I donot know why the item is getting disable sometimes when click on item.

jpn
26th December 2007, 12:19
How do you react to check state changes? Show the slot, please.

vishal.chauhan
26th December 2007, 12:29
Actually I m updating the state of the current item parent in the treeWidget and link list.

It has 4 function which i m using and its not possible to post them.
But I can assure that they all are running well in Qt 4.2.2 but donot know why there is a problem in the Qt 4.3.2.

Even if I donot use them then still the item is not checked.

wysota
26th December 2007, 13:31
Can you provide a minimal compilable example reproducing the problem?

vishal.chauhan
27th December 2007, 08:52
Hi,

I m attaching a code.In it i have a treeWidget on which when i clicked sometimes item is not checked or unchecked.

jpn
27th December 2007, 09:00
Does it work properly with another style, for example with plastique?

./app -style plastique

vishal.chauhan
27th December 2007, 09:25
Yes the problem remains even after changing the Style.

vishal.chauhan
28th December 2007, 04:40
Hi,

No Answer????.
So Am I right it a problem of qt 4.3.2:crying:

jpn
28th December 2007, 06:29
The only problem I'm experiencing with 4.3.2 is that the area that responds to check state changes is a bit too far left. With 4.3.3 it works perfectly.

vishal.chauhan
28th December 2007, 09:05
Hi jpn,

So you are saying that if I use qt 4.3.3 then this problem should not arise.

jpn
28th December 2007, 09:40
I can't say for sure. Your description "sometimes item is not checked or unchecked" is vague.

As I said, for me with Qt 4.3.2 check states change but I can notice that the area that reacts to checking is a bit too left, not exactly over the drawn check box (see the attached explanatory screenshot). With Qt 4.3.3 it reacts exactly over the drawn check box.

vishal.chauhan
28th December 2007, 11:21
By saying "Sometimes item is not checked or unchecked" I mean that sometimes item check state change on the signle click and sometimes I click several times on item and its check state does not changed.

jpn
28th December 2007, 11:41
sometimes item check state change on the signle click and sometimes I click several times on item and its check state does not changed.
Even if you keep mouse at exactly the same position? I don't have such problem with Qt 4.3.2.

wysota
28th December 2007, 12:23
Maybe this is OS specific? I don't have 4.3.2 installed anywhere so I can't verify it here, but if J-P tested it and it worked fine, then I don't see why it should fail elsewhere. Could you check if the same thing happens when using examples bundled with Qt?

vycke
3rd January 2008, 20:18
It appears that the check box in a tree (or list) view doesn't change when checked (4.3.2) -- which if fixed in 4.3.3 means I can remove some code I added to "fix" it.

I added a:


connect(m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(clickCheck(QListWidgetItem*)));

and for the slot:



void clickCheck(QListWidgetItem* item)
{
if (item->checkState() == Qt::Unchecked)
item->setCheckState(Qt::Checked);
else
item->setCheckState(Qt::Unchecked);
}


This allows the user to click on the label for the check box & get the box toggled. (Boy, I hope 4.3.3 allows me to remove this code... although it makes it nicer for users, maybe I'll keep it either way)

Vycke