[PyQt] QCheckBox problem
Jim Bublitz
jbublitz at nwinternet.com
Mon Jan 5 03:43:24 GMT 2009
On Sunday 04 January 2009 17:30:41 pm Doug Hackworth wrote:
> Greetings. This should be an easy one for someone to answer.
>
> Simple situation: I have a QCheckBox on a main window along with
> other widgets, but mysteriously it won't do anything. Since all my
> other widgets (buttons, mainly) do what they're supposed to, I
> suspect I am using the QCheckBox incorrectly. It's the first time
> I've tried using one.
>
> I am attempting to connect the checkbox's "toggled()" signal to a
> slot with this line:
>
> <code>
> QtCore.QObject.connect(self.ui.checkMyCheckbox,
> QtCore.SIGNAL("toggled()"), self.MyCheckboxSlotFunction)
> </code>
>
> Here is the slot I have defined for it:
>
> <code>
> def CheckMultiMask(self):
> sys.stdout.write("checkbox toggleded\n")
> if (self.ui.checkMyCheckbox.isChecked()):
> sys.stdout.write("it's checked\n")
> </code>
>
> When the window loads, however, I can click on the QCheckBox all I
> want, to no avail. Also, the application object doesn't complain
> when it loads, and I know it's getting to the connect() invocation
> quoted above... I just don't know why the slot function doesn't seem
> to ever be invoked. And again, my other widgets with signals/slots
> connected by me (in a manner like that above) are behaving as
> expected.
>
> Any thoughts from the experts? I'll be happy to provide further
> information on context if it's useful.
>
> BTW, I'm using Ubuntu 7.10 and the following versions of PyQt / Qt:
> $ pyuic4 --version
> Python User Interface Compiler 4.3 for Qt version 4.3.2
>
> (The MainWindow was constructed with Qt Designer by way of pyuic4.)
If the code you've provided is what you actually have, you haven't
connected the signal to the slot you show - instead of
self.MyCheckboxSlotFunction, you should be connecting to
self.CheckMultiMask.
If that isn't the problem, it'd help someone to figure it out if you
could provide a complete small executable program that exhibits the
problem behavior.
Jim
More information about the PyQt
mailing list