[PyQt] Signal on Selection in QTreeView

Andreas Pakulat apaku at gmx.de
Tue Mar 18 00:00:36 GMT 2008


On 17.03.08 16:31:54, Kevin Foss wrote:
>    Your understanding seems to correct.   I do not want to change the list 
> entries at this point.  To confirm what you said, I do want to have the item 
> details of a list entry displayed in a separate widget when the user selects 
> the list entry.  Part of the explanation below was an idea to get the row 
> number of the currently selected list item and then display that individual 
> list item in the other widget.  

Ok, so you really want to be notified whenever a selection change
happens so you can update your other widget. Then connect a slot to the
selectionChanged() signal from your views QItemSelectionModel. That slot
needs 3 arguments: self, selected, deselected. The 2nd one is of
interest for you, it is a QItemSelection which provides a list of
QModelIndexes that are in the selection (via the indexes() method). You
can simply take the first element from that list (check that its not
empty before doing so) and ask your model for the data of that index.
How you do that depends on wether your custom model has a way of
returning an instance of your underlying data structure for a model
index. If not you can simply use the data() function that all models
have and ask that for the needed data.

Andreas

-- 
Don't look now, but the man in the moon is laughing at you.


More information about the PyQt mailing list