PDA

View Full Version : Detect ONLY when a QTreeWidgetItem text has been edited.



cgahete
29th August 2013, 16:49
Hello,

I've been searching the forum but didn't find any clue about the following doubt:

I have a QTreeWidgetItem that I have made it editable:



pItem->setFlags(pItem->flags() | Qt::ItemIsEditable);


If I use:



connect(tree->treeWidget, SIGNAL(itemChanged( QTreeWidgetItem *, int)), (Tree*)tree, SLOT(foo()))


it detects not only when it has been edited, but also if its icon has changed.

1) Is there an easy way to detect only when its text has been changed?

2) The connect code that I use detects changes in any item of the tree. How can I make it to trigger only for a certain Item of the tree?


Thank you in advance,

Santosh Reddy
29th August 2013, 20:20
1) Is there an easy way to detect only when its text has been changed?

2) The connect code that I use detects changes in any item of the tree. How can I make it to trigger only for a certain Item of the tree?
Add parameters to slot foo() and inside the slot function check for the item and role

cgahete
30th August 2013, 09:40
Thanks for you answer,

and how could I detect only when its text has been changed? Not a setIcon or something like that.

Santosh Reddy
30th August 2013, 12:12
when role == Qt::DisplayRole

cgahete
30th August 2013, 13:09
I dont use any model. Can I use a role in my case?

Santosh Reddy
30th August 2013, 13:18
Oops, sorry my mistake.

When using QTreeWidget it will not be possible. Any change will trigger the signal, filtering for text change is not possible.