tags:

views:

98

answers:

1

Hi,

I'm trying to create a list of checkbox items that change the status on activation. I can connect the activate signal and everything seems to work, but changes on the screen. Am I missing some steps here?

Here's the list creation:

self.listField = QtGui.QListWidget(self)

muted_categories = qb.settingsCollection['mutedCategories'].split('|')
main_categories = sorted(set(qb.categoryTopNames.values()))

for category in main_categories:
   item = QtGui.QListWidgetItem(category, self.listField)
   item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
   if category in muted_categories:
      item.setCheckState(QtCore.Qt.Checked)
   else:
      item.setCheckState(QtCore.Qt.Unchecked)

self.listField.connect(self.listField, QtCore.SIGNAL('itemActivated(QListWidgetItem*)'), self.doItemChangeState)

and here's the handler:

def doItemChangeState(self, item):
   """ invert the state of the activated item """

   if item.checkState() == QtCore.Qt.Checked:
      item.setCheckState(QtCore.Qt.Unchecked)
   else:
      item.setCheckState(QtCore.Qt.Checked)

I verified that the handler is fired after clicking - if I put prints there, it will alternate "checked" / "unchecked". What can I do to refresh the checkboxes themselves?

Edit: tried calling update() and emitting the itemChanged signals... no luck so far.

+2  A: 

I can't test this just now, but... I was under the impression that PyQt4 handled the screen updates automatically when items were checked/unchecked (at least, it does for QCheckBox items). It looks to me like your event handler is actually undoing the user's action. Have you tried commenting out the self.connect line and running again?

As I understand it, setCheckState() is really intended for setting the default state of each item...

Rini