Model: ItemIsUserCheckable
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 ?
Re: Model: ItemIsUserCheckable
Ok, I should be (a very bit?) stupid!
The fault was in my "delegate" where I do only something like this:
Code:
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" ?
Re: Model: ItemIsUserCheckable
When I replace my delegate by a simple QItemDelegate, the 'check' behavior is as I excepted, but when I had only the method:
Code:
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 ?
Re: Model: ItemIsUserCheckable
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.
- If you want only certain items to be non-editable, don't return "ItemIsEditable" for them!