[Qt-interest] General problem with selection in QAbstractItemView classes (QListXXX QTreeXXX etc)

Zeljko zeljko at holobit.net
Wed Jun 29 13:55:01 CEST 2011


Hi,
Just found an interesting problem with selection behaviour inside 
QAbstractItemView classes (no matter which class it is QListView, QListWidget, 
QTreeView, QTreeWidget ... even created my own QTreeView with QStandardItemModel 
and my QItemSelectionModel etc etc). I've used selection signals for such 
purpose but now I need accurate information (need it for my QTreView + 
QStandardItemModel) when mouse is pressed so:

1.MousePress event in itemView viewport
2.You can clearly see that item is selected (colored blue, focus rect around it 
...)
3.Ask that item is it selected ... NO ?!?
4.Ok ask Selection model about that selection ? NO ?!?

5.MouseRelease .... ahh item says that's selected :( ...it's too late.

That's pretty nasty. You can see selected item but code says that item isn't 
selected :(
I can understand such behaviour in case when item is checkable and mouse is 
inside checkbox (so we cannot trigger such change because user can move mouse 
and release it ... checkbox shouldn't be updated...that works correct), but 
simple selection is wrong, because selection is updated when mouse is released 
and that's too late (it's already selected *visually* by mousepress).

IMO, if user see selected item on the screen , our item data should be already 
updated.

Maybe I should use QTreeView event filter not viewport ? 

Any clues / comments ? Should I open an issue about this ?

zeljko





More information about the Qt-interest-old mailing list