[PyQt] QCheckBox in a QTreeWidget

David Boddie david at boddie.org.uk
Fri Sep 5 23:21:15 BST 2008


On Fri Sep 5 22:19:22 BST 2008, Jake Richards wrote:

> I've done a bit of googling and looked at the docs but haven't seen an
> example of how to place a checkbox (or other widgets) into a QTreeWidget.

You need to change the flags for the item so that it is editable:

http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qtreewidgetitem.html#setFlags

The flags themselves are described here:

  http://doc.trolltech.com/4.4/qt.html#ItemFlag-enum

You can create an item and set the flags you want, like this:

  item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsUserCheckable)

or combine the default flags with the ones you want:

  item.setFlags(item.flags() | Qt.ItemIsEnabled)

Then you'll probably need to set the initial state of the item, like this:

  item.setCheckState(0, Qt.Unchecked) # 0 is the column number

This is probably easier than inserting an actual widget into the tree.

David


More information about the PyQt mailing list