PDA

View Full Version : QTreeWidget selection



adhit
23rd April 2008, 21:50
Hello!

I have a problem. My program's functionality depends on type of current item in QTreeWidget and of the count of selected items:



// Signal currentItemChanged(...) handler
void Class1::Handler(QTreeWidgetItem* pCurItem, QTreeWidgetItem * pPrevItem)
{
..
if (tree->selectedItems().count() > 1)
{
...
}
else
{
if (pCurItem->data(0, Qt::UserRole).toString() == "example1")
{
...
}
else
{
...
}
}
}


QTreeWidget selection mode is ExtendedSelection.
For example, i select in tree 5 items (by mouse). It works correct.
> Item1
> Item2
> Item3
> Item4
> Item5

Then, i click to one item of that 5.
Item1
Item2
> Item3
Item4
Item5

And here is the problem. My handler works as if it was selected 5 items...Maybe QTreeWidget class has some function, that force tree to refresh selected list?

Thank you!

merlvingian
24th April 2008, 09:41
Since Item3 is one of the items already selected along with item1-item5 it will not trigger currentItemChanged() when you click on it.

You would also need to connect itemClicked() in combination with your current setup for the result you desire. This will also have the side effect of both calls being triggered if the item was not previously selected.

adhit
24th April 2008, 13:24
Thank you! Now it works. I handled currentItemChanged() and itemSelectionChanged() and it works by mouse selection and keyboard too.

jpn
25th April 2008, 09:08
Keep in mind that "current item" and "selected items" are related but still different concepts. Current item is the one which has keyboard focus. There can never be more than one current item. However, depending on the selection mode, there can be one or multiple selected items. It's also possible that none of selected items is current item (keyboard navigation).