Using Checkboxes in QT

Hi there.

I’m trying to build a UI with QT. Never done this before.
I would like to use some checkboxes but i dont get the SIGNAL Stuff working.

My Interfaceclass sends now on every slotchange a signal.

#Interface Class
class Interface(base_class, form_class):
    def __init__(self):
        super(base_class, self).__init__()
        self.setupUi(self)
        self.setObjectName('Highscorelist')
        self.setDockNestingEnabled(True)
        self.Establish_Connections()
    def createBox_fn(self):
        polyCube()
    def Establish_Connections(self):
        QtCore.QObject.connect(self.recordBox, QtCore.SIGNAL("stateChanged(int)"),self.createBox_fn)

How do i get the on/off state of my checkbox to execute different functions?

Thxs for any help :slight_smile:

Try something like this. This is the new signal/slot syntax. Here’s a link to some docs. http://qt-project.org/doc/qt-4.8/signalsandslots.html

self.recordBox.stateChanged(int).connect(lambda:self.createBox_fn())

It’s a shame so many pyqt examples have that old signal syntax. It is probably responsible for most of the misunderstandings about Qt (it was responsible for all of mine). Once you learn the new syntax, Qt becomes really easy and intuitive.

Michael: That lambda needs to take arguments. So it’d have to be: “.connect(lambda *_:self.createBox_fn())”, or “.connect(self.createBox_fn)” would be preferable if it does not take any arguments.