[PyQt] setEditTriggers

Andreas Pakulat apaku at gmx.de
Sun Jul 20 09:27:59 BST 2008


On 19.07.08 21:45:28, Scott Frankel wrote:
>
> Problem found:  I needed to implement flags() and setData() in my model.  
> I knew it was going to be something I overlooked.
>
> Better question(s):
>
> - What's the proper way to implement setData() for a tree model?  I've  
> extended QAbstractItemModel with methods that add branches and leaves to 
> populate the tree in the first place.  Does setData() call them again?  

Probably not. setData() is there to change the data of existing items in
the model. Not to add new data - at least not with the Qt::EditRole.

> - How can flags() be coaxed to make only one column's fields editable?

flags() has the item as parameter so you can just check its column value
and return different flages based on that.

> I'm on to exploring delegates next, to give my editable tree fields  
> comboboxes.

Yeap for arbitrary data you'll need that. IIRC Qt only supports combobox
editor for boolean values (i.e. if data() returns a boolean)

BTW: Qt4.4 contains an editable tree model example so you might want to
have a look at that. It only enables editing of plain strings, but its
probably a good starting point nonetheless.

Andreas

-- 
You will be married within a year, and divorced within two.


More information about the PyQt mailing list