[PyQt] Easy Question - How to use selectionChanged on a QTreeView?

Florian Bruhin me at the-compiler.org
Sun Nov 20 22:33:51 GMT 2016


* Richie Ward <richies at gmail.com> [2016-11-20 22:27:13 +0000]:
> As I understand it, I have to use
> setSelectionModel(MySelectionModel()) and subclass
> QItemSelectionModel. I can then override selectionChanged. My attempts
> to do this have resulted in this error:
> QAbstractItemView::setSelectionModel() failed: Trying to set a
> selection model, which works on a different model than the view.

That's a signal, so you should be able to simply do:

    view.selectionModel().selectionChanged.connect(selection_changed)

And then handle it in there, without subclassing anything.

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161120/bfa644ad/attachment.sig>


More information about the PyQt mailing list