PDA

View Full Version : QTreeView selection strangeness



jkv
7th December 2009, 12:34
Hi,

I've QTreeView + custom Model that returns Qt::ItemIsSelectable flag only for some of the items. View selection mode and behaviour are set to QAbstractItemView::ExtendedSelection & QAbstractItemView::SelectRows.

Clicking on item that hasn't got Qt::ItemIsSelectable flag set I get selectionChanged(..) signal from the SelectionModel.

What makes this confusing is that QItemSelectionModel::selectedIndexes() and QItemSelectionModel::selectedRows() returns at this point empty list but QItemSelectionModel::hasSelection() returns 'true'. This same behaviour persists even if I call the functions in other places later and haven't touched the selections in any way since the selectionChanged(..)

Is this how it's supposed to work or is there some problem in my code (probably model.cpp) ? I've attached src of small test program that shows the behaviour. By pressing F1 it shows current selection info. Anyone else get the same strange result ?

Qt source didn't give any positive answers to me and reading Qt docs doesn't clearly tell that selectedRows() and hasSelection() somehow mean different set of selections...

Im running Qt 4.5.3 on linux but I remember this problem(?) being present also in earlier version(s).

Thanks

jkv
11th December 2009, 06:50
Well noticed another problem in the app I posted.

If I first select all items in the View and then start ctrl-deselecting rows, QItemSelectionModel::rowsSelected() returns wrong values: at times it decreases by more than one and at other times it can even increase. However QItemSelectionModel::selectedIndexes() does decrease always by 2 which is correct because there are only 2 columns in the model.

So after that I slightly modified the Qt SimpleTreeModel-example (just to get input when selections change) and noticed the same problem even then...

Anyone willing to test out the code I posted and report if this same thing happen for you ? I wouldn't want to start blaming qt quite yet :)