[PyQt] problem with setItemDelegateForColumn and ItemIsUserCheckable

David Boddie david at boddie.org.uk
Wed Jun 6 01:55:11 BST 2007

On Fri, 1 Jun 2007 09:56:25 -0500, Brian DeWeese wrote:

> I have a 2 column QTableView where column 0 is checkable and column 1 is
> editable.  I've written a custom editor by implement QItemDelegate which is
> working fine.  Also, the checkbox in column 0 is also working fine.  But
> not both at the same time.
> If I use view.setItemDelegate(myDelegate) than my delegate is called to
> create my custom editor and everything about column 1 works correctly.  But
> column 0 doesn't work correctly. It is displaying a checkbox with the
> correct current value but clicking on it does not call my model's setData()
> method or do anything at all as far as I can tell.

OK. This doesn't sound right.

> If I use view.setItemDelegateForColumn(1, myDelegate) than the checkbox in
> colum 0 works but double-clicking on column 1 will ignore my delegate and
> create a default editor.

Did you create the delegate in a way that stops it from being garbage
collected and subsequently deleted on the C++ side? In other words,
did you store the instance somewhere, or create it with a parent QObject?

I'm guessing that you did, otherwise you wouldn't see your editor in the
previous situation. :-/

> Is this a known bug in either PyQt or Qt itself?  Or am I doing something
> wrong?

I would like to see more code before declaring something wrong with
setItemDelegateForColumn() in either Qt or PyQt.

> I'm using PyQt 4.1.1 with Qt 4.2 on SUSE 10.1.  (BTW, Is there a proper way
> to verify that I'm using the versions that I think I'm using?)

from PyQt4 import pyqtconfig

> Here is my model.flags() method.
>     def flags(self, index):
>         if not index.isValid():
>             return QtCore.Qt.ItemIsEnabled
>         if index.column() == 0:
>             return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable |
> QtCore.Qt.ItemIsUserCheckable

You might want to make this editable, too.

>         elif index.column() == 1:
>             return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable |
> QtCore.Qt.ItemIsEditable
>         return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable

Hope this helps,


More information about the PyQt mailing list