[PyQt] Signal on Selection in QTreeView

Kevin Foss fossks at cox.net
Tue Mar 18 01:57:52 GMT 2008


Andreas,
	I am sorry but I am still not seeing the whole picture.  I've been through my 
reference books as well as just about any page that exists online that talks 
about selection models and I just can't put 2 and 2 together.

	To show you my difficulties, I've tried to test this whole selection model 
capability using an example from David Boddie at Trolltech.  It can be found 
here:

http://www.opensubscriber.com/message/pyqt@riverbankcomputing.com/8447872.html

      	Guess what, even his example doesn't work.  When I run his example, 
nothing is printed when an item is selected.

	I've spent alot of time programming my mplayer frontend which uses media that 
has been imported into the library.  A set up an initial library by hand, but 
now I need to create the library manager and being able to highlight/select 
and entry and see the details is the most basic function.

	I could really use a link to a complete example that shows the proper setup 
of a model, indexing and the selection of an item.

	I appreciate your efforts.  I'd hate to give up on the project at this point.

Kevin

On Monday 17 March 2008 05:00:36 pm Andreas Pakulat wrote:
> 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




More information about the PyQt mailing list