I have a groupbox which is always enable. I want it to be enable only when user want to edit something, so I made a checkbox for it. However, I have no idea how to 'link' if checkbox if selected with groupbox switching on. I want groupbox to be greyed out when disable.
1 Answer
This works for me:
from PyQt4.QtGui import QGroupBox, QCheckBox, QDialog, QHBoxLayout
d = QDialog()
gb = QGroupBox("Groupbox")
gb.setEnabled(False)
cb = QCheckBox("Set active")
l = QHBoxLayout(d)
l.addWidget(gb)
l.addWidget(cb)
cb.stateChanged.connect(toggleGroupBox)
def toggleGroupBox(state):
if state > 0:
gb.setEnabled(True)
else:
gb.setEnabled(False)
This connects a function which toggles the Groupbox to the signal which is emitted by the checkbox whenever it gets clicked.