PDA

View Full Version : [4.6] QTreeView Clicked() signal returns column specific data



Guilo
22nd January 2010, 22:01
Hi all!

I am using a QTreeView whith 5 columns. The first one, labelled id contains a number. This number is used to retrieve information in an database. So I use the clicked signal : when I click on a line on the qtreeview, I can access the data I have clicked on (index.data(0)). But this behaviour forces me to click on the id column to get the information related to this line. Indeed, if I click any other column, a unrelevant qstring is catched and I can't use it to retrieve info in the db.

What I would like is that whatever the column I click on, it returns me the value stored in the first column.

I have seen row function but it is not suitable here as I use a QSortFilterProxyModule so if I filter the model, the row column isn't the right value.


Thanks

Coises
23rd January 2010, 22:04
I have seen row function but it is not suitable here as I use a QSortFilterProxyModule so if I filter the model, the row column isn't the right value.

Unless you’re either filtering out the first column, putting it in an unpredictable column, or putting columns from different source rows into one target row, index.sibling(index.row(), 0).data() should still work.

If that really can’t work because of the filtering, then perhaps you could use QSortFilterProxyModel::mapToSource to get the source model index, then retrieve what you need directly from its appropriate sibling in the unfiltered model.