Setting checkstate on a ListWidgetItem

Posted by viraptor on Stack Overflow See other posts from Stack Overflow or by viraptor
Published on 2010-04-05T18:38:24Z Indexed on 2010/04/05 18:43 UTC
Read the original article Hit count: 351

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about qt4

Related posts about pyqt4