1

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

1 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.