[PyQt] qtreeview and custom display roles

Adam Tenderholt atenderholt at gmail.com
Sat Jun 14 23:16:48 BST 2008


I'm trying to creating something akin to an phonebook. For a given
person, there are possibly two phone numbers listed (say work and
cell). What I'm trying to implement is single model (PhoneModel) and
two different views (WorkView and CellView). My initial thought was
that I should use two custom display roles (WorkRole and CellRole).
With that in mind, I have two questions:

1) Is there a way to coerce a QTreeView into asking for the WorkRole
and CellRole data instead of DisplayRole for WorkView and CellView? Or
do I need to need to create my own views subclasses based on

2) Is there a way to tell QTreeView to not display an entry if it is
missing (ie. Fred doesn't have a cell phone, so he shouldn't show up
in CellView)?

Is it possible to do both of these without going through the trouble
of creating my own ItemView? And if not, what functions do I need to
re-implement from QAbstractItemView? I'm not finding any of the
examples too helpful.

Thank you for your time,


More information about the PyQt mailing list