[PyQt] Signal on Selection in QTreeView

Andreas Pakulat apaku at gmx.de
Tue Mar 18 21:48:48 GMT 2008


On 18.03.08 13:37:46, fossks at cox.net wrote:
> I have been successful in getting the row number back to me for a selected row.  I have found that the returned row number is not consistent with the list but with the view.  Therefore row '0' when I start is row '10' on a 10 item list when the view is sorted in the opposite direction.
> 
> Is there a simple method of retrieving the item data out of the list model for the selected item?

You seriously need to read the documentation on the model/view framework
in Qt. http://doc.trolltech.com/4.3/model-view-programming.html

In short: You can retrieve the model indexes from the selection, with
that index you can ask the model itself for the data of that index via
the model's data() function. That function takes an index, a role
(usually you want Qt.DisplayRole here, but it may also need a custom
role, that depends on the implementation of the model). This will return
a QVariant carrying the data, you just need to get out the actual data
(string, integer, list and so on) and can then populate the custom
widget.

Andreas

-- 
You have been selected for a secret mission.


More information about the PyQt mailing list