[PyQt] signal issue with qbuttongroup

Di Zou di_zou at yahoo.com
Thu Aug 4 21:38:10 BST 2011


My code is based on classes. This is how my code looks right now:

class MyWidget(QWidget):
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        self.Function()

    def Function(self):
        addAppButtonGroup = QButtonGroup()
        addAppButtonGroup.addButton(addCustomAppButton)
        addAppButtonGroup.addButton(addAppleStoreAppButton)
        addAppButtonGroup.addButton(addWebLinkButton)

        addAppButtonGroup.setId(addCustomAppButton, 0)
        addAppButtonGroup.setId(addAppleStoreAppButton, 1)
        addAppButtonGroup.setId(addWebLinkButton, 2)        
 
        self.connect(addAppButtonGroup, SIGNAL("buttonClicked(int)"), self.AddApplication)

        """
        Code that makes the buttons show up on screen
        adding layouts, adding widgets, etc
        """

    def AddApplication(self, id):
        print "hi"
        print id

Like I said, all the buttons show up and are clickable. When I click on a button, nothing happens.

----- Original Message -----
From: Mike Ramirez <gufymike at gmail.com>
To: Di Zou <di_zou at yahoo.com>
Cc: 
Sent: Thursday, August 4, 2011 4:17 PM
Subject: Re: [PyQt] signal issue with qbuttongroup

On Thursday, August 04, 2011 12:52:39 PM Di Zou wrote:
> I switched to:
> 
> def AddApplication(self, id):
>     print "hi", id
> 
> I also removed this:
> 
> addAppButtonGroup.setId(addCustomAppButton, 0)
> addAppButtonGroup.setId(addAppleStoreAppButton, 1)
> addAppButtonGroup.setId(addWebLinkButton, 2)
> 
> and it still doesn't work.
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Is your code based on classes or functions only?

Qt woirks best when you're using classes in a module, if not things don't see 
each other without globals.

If it's classed based, you need to pass 'self' to the methods and use that. 
self is similar to the c++ keyword 'this' and refers to the class instance.


Mike
-- 
"I may kid around about drugs, but really, I take them seriously."
- Doctor Graper


More information about the PyQt mailing list