QAbstractItemView behaves so that when a mouse press event is received, the selection is applied first and then the current index is set afterwards changing the selection. So by the time selection change is informed through signal, QAbstractItemView has not yet set the current index. So what happens here is that still if you change the current item to something else, QAbstractItemView comes and resets it back to the pressed index.
One idea to solve this would be to delay the changing of the current item:
// A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed
QTimer::singleShot(0,
this,
SLOT(setLastItemCurrent
()));
void MyForm::setLastItemCurrent()
{
// get "LastItem" somehow or store is as a member variable or something..
TreeWidget->setCurrentItem(LastItem);
}
// A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed
QTimer::singleShot(0, this, SLOT(setLastItemCurrent()));
void MyForm::setLastItemCurrent()
{
// get "LastItem" somehow or store is as a member variable or something..
TreeWidget->setCurrentItem(LastItem);
}
To copy to clipboard, switch view to plain text mode
Bookmarks