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.
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.
If you provide a stop condition, you will prevent recursing.
GNU/Varan (13th May 2011)
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 evenQt Code:
ui.subprograms->setCurrentItem(prev); ui.subprograms->selectionModel()->select(ui.subprograms->currentIndex(), QItemSelectionModel::SelectCurrent);To copy to clipboard, switch view to plain text mode
in my "currentItemChanged"-handler but this has no effect. Seems like selection automatically changes after the current item.Qt Code:
ui.subprograms->setCurrentItem(prev); prev->setSelected(true);To copy to clipboard, switch view to plain text mode
Should I overrideas well?Qt Code:
void QAbstractItemView::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )To copy to clipboard, switch view to plain text mode
You should connect to QItemSelectionModel's selectionChanged() signal.
GNU/Varan (17th May 2011)
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.
Last edited by yren; 19th July 2011 at 19:50.
Bookmarks