The question as well relates to other QAbstractItemView derivates.
I want to check some condition if I go to new current item. If it fails - then nothing should happen, and current item should remain the same.
Printable View
The question as well relates to other QAbstractItemView derivates.
I want to check some condition if I go to new current item. If it fails - then nothing should happen, and current item should remain the same.
Very good. And?
If you provide a stop condition, you will prevent recursing.
By the way - how to deal with selection? It's independent of current item so I run into situation when the current item is right whereas the selected item is wrong.
How do you want to "deal" with it? You have the selection model and you can manipulate it as you want.
But in what function must I manipulate it? I do something like
or evenCode:
ui.subprograms->setCurrentItem(prev); ui.subprograms->selectionModel()->select(ui.subprograms->currentIndex(), QItemSelectionModel::SelectCurrent);
in my "currentItemChanged"-handler but this has no effect. Seems like selection automatically changes after the current item.Code:
ui.subprograms->setCurrentItem(prev); prev->setSelected(true);
Should I overrideas well?Code:
void QAbstractItemView::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )
You should connect to QItemSelectionModel's selectionChanged() signal.
I had the same problem as yours. It seems like QT is not capable of handling this situation. Since the actual change of the selection happens after the slot returns, and while in the slot, the prev item is still the "current" item, so setCurrentItem(prev) in the slot won't do anything new. In MFC, you can set a flag bit in the event to tell the system not to set the selection change so the old selection will still be valid after the event handler returns.