Hi,
I'm having difficulty selecting an item and drawing a focus rect on it at the same time.
What I want to do is: in a single-selection mode tree widget if the last selected item does not pass a test when the user clicks a different item I want to move the selection & focus rect back to the last selected item. The last item can be re-selected without problem, however, the focus rect always seems to stay on the item the user just clicked.
Please help if any of you has done this before.
void MyForm::OnTreeWidgetItemSelectionChangedSlot()
{
. . .
//TreeWidget has single selection mode.
//This slot is in response to the itemSelectionChanged signal.
SelectedItemList = TreeWidget->selectedItems();
if (SelectedItemList.count() > 0)
{
//Get the newly selected item.
Item = SelectedItemList[0];
if (LastItem failed the validation test)
{
//Unselect the newly selected item.
Item->setSelected(false);
//Set the selection & focus back to the last item.
LastItem->setSelected(true);
TreeWidget->setCurrentItem(LastItem);
}
else
{
LastItem = Item;
...
}
}
}
void MyForm::OnTreeWidgetItemSelectionChangedSlot()
{
. . .
//TreeWidget has single selection mode.
//This slot is in response to the itemSelectionChanged signal.
SelectedItemList = TreeWidget->selectedItems();
if (SelectedItemList.count() > 0)
{
//Get the newly selected item.
Item = SelectedItemList[0];
if (LastItem failed the validation test)
{
//Unselect the newly selected item.
Item->setSelected(false);
//Set the selection & focus back to the last item.
LastItem->setSelected(true);
TreeWidget->setCurrentItem(LastItem);
}
else
{
LastItem = Item;
...
}
}
}
To copy to clipboard, switch view to plain text mode
Thanks,
TM
Bookmarks