PDA

View Full Version : Model: ItemIsUserCheckable



weepdoo
15th October 2007, 11:20
Hye all :)

I'm still trying to create my own ItemModel for my data structure in PyQt.
This model is quiet "readable only" (and now it works great thanks to you ;) ).
But I would like my users to be able to check a check box (that represent a boolean value).

For this column, I use the flag:
QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEditable

The data are correctly display, but my user can't 'check' this check box.
I add a setData method to my model, but it do not seems to be called at all.

What am I doing wrong ?

weepdoo
15th October 2007, 11:33
Ok, I should be (a very bit?) stupid!

The fault was in my "delegate" where I do only something like this:



def editorEvent(self, event, proxyModel, option, proxyIndex):
eventType = event.type()
if eventType == QtCore.QEvent.MouseButtonDblClick:
[...] # <- we do not care
return True
return False


Should I do something "else" ?

weepdoo
15th October 2007, 15:34
When I replace my delegate by a simple QItemDelegate, the 'check' behavior is as I excepted, but when I had only the method:


def editorEvent(self, event, proxyModel, option, proxyIndex):
eventType = event.type()
if eventType == QtCore.QEvent.MouseButtonDblClick:
[...] # <- we do not care
return True
return False


The check do not work anymore...
Any idea ?

jpn
19th October 2007, 04:19
Well, filtering out mouse events is not a very good way of implementing "read-only" functionality.

If you want the whole view to be non-editable, adjustQAbstractItemView::EditTriggers (http://doc.trolltech.com/latest/qabstractitemview.html#EditTrigger-enum).
If you want only certain items to be non-editable, don't return "ItemIsEditable" for them!