I have written following piece of code using PyQt.

Qt Code:
  1. class QChoices(QWidget):
  2.  
  3. def __init__(self):
  4. QWidget.__init__(self)
  5. self.setLayout(QVBoxLayout())
  6. policy = QSizePolicy()
  7. policy.setVerticalPolicy(QSizePolicy.Minimum)
  8. self.setSizePolicy(policy)
  9.  
  10. def addChoice(self, choice):
  11. checkBox = QCheckBox(choice)
  12. checkBox.setCheckState(Qt.Checked)
  13. self.connect(checkBox, SIGNAL('stateChanged(int)'), self.remove)
  14. self.layout().addWidget(checkBox)
  15.  
  16. def remove(self, state):
  17. if state != Qt.Unchecked:
  18. raise Exception('Choice checked back again!')
  19. self.sender().hide()
  20. self.sender().deleteLater()
  21. self.updateGeometry()
To copy to clipboard, switch view to plain text mode 

It is supposed to work like attachments in GMail, where you can uncheck a check box to remove an attachment and it disappears. So it works ok, but the problem is, that the widget doesn't resize itself to be smaller again, when one of the checkboxes is hidden. I have set vertical size policy in this widget and in parent widget to Minimum, but it doesn't help. I just can't figure out, how to make it resize itself properly. Could anyone help me with this?