Hello > -----Original Message----- > From: [email protected] [mailto:pyqt- > [email protected]] On Behalf Of dizou > Sent: June-22-10 2:11 PM > To: [email protected] > Subject: [PyQt] Problem connecting buttonClicked signal > > > I have a bunch of QPushButtons in a QButtonGroup. I am trying to connect the > buttonClicked() signal with a method, but I am not able to. > > This is what I have: > > class DrawWidget(QWidget): > def __init__(self, parent): > QWidget.__init__(self, parent) > > self.Setup() > def Setup(self): > cursorButton = QPushButton() > platformButton = QPushButton() > nodeButton = QPushButton() > channelButton = QPushButton() > > buttonGroup = QButtonGroup() > buttonGroup.setExclusive(True) > buttonGroup.addButton(cursorButton, 0) > buttonGroup.addButton(platformButton, 1) > buttonGroup.addButton(nodeButton, 2) > buttonGroup.addButton(channelButton, 3) > > for button in buttonGroup.buttons(): > button.setFlat(True) > button.setCheckable(True) > > cursorButton.setChecked(True) > gridLayout = QGridLayout() > gridLayout.addWidget(cursorButton, 0, 0) > gridLayout.addWidget(platformButton, 0, 1) > gridLayout.addWidget(nodeButton, 0, 2) > gridLayout.addWidget(channelButton, 0, 3) > > self.setLayout(gridLayout) > > self.connect(buttonGroup, SIGNAL("buttonClicked(int)"), > self.ButtonClick) > #self.connect(buttonGroup, SIGNAL("clicked(int)"), self.ButtonClick) > def ButtonClick(self, id): > print id > print "clicked" > > When I run this code, I don't get anything printed on the screen.
The reason you don't get anything is because "buttonGroup" is being garbage collected because it goes out of scope after "Setup" is completed. You have to set it to "self.buttonGroup" so that something holds reference to it. Darryl _______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
