guineapig at pi.be
Tue Sep 2 12:34:01 BST 2003
Fredrik Juhlin wrote:
> GuineaPig wrote:
>> I'm working with pyQt and I have a widget with 40 QPushButtons
>> (toggles). On 'toggled()' the buttons emit a signal to a function. In
>> this function I'd like to find out wich button was pressed. I'm
>> thinking about iterating through all the buttons to check theirs
>> state but I can't seem to find how to do this in the docs. Can
>> someone point me in the right direction ? Should I handle this
>> differently ?
> You might want to look at QButtonGroup. If you add all your buttons to
> a button group, you can listen to QButtonGroup.clicked()to find out
> what button was clicked.
> If that doesn't work for you you'll probably have to subclass
> QPushButton and create your own signal that supplies the button itself
> to the slot.
I think the QButtonGroup-solution will do fine... One problem though...
I've constructed the buttons in Qtdesigner and named them pushButton1
--> pushButton40. Since all the buttons are similar I constructed them
by cutting and pasting... Problem is now that the id's do not seem to
match the order of the buttons. Is there a way to set the id of a button
in a buttongroup. The only thing I find is that you can specify the id
when you add buttons through QButtonGroup.insert(QButton button, int
More information about the PyQt