[PyKDE] Sending an argument to a function with a button click
Andrew Bushnell
awb at fluent.com
Tue Aug 5 13:11:01 BST 2003
This idea sounds good. Another alternative that might work would be to
put all the buttons in a QButtonGroup and connect to the clicked(int)
slot of the buttonGroup. Each button is assigned an ID starting at 0 (I
believe) as you add them to the group, or you can insert them yourself,
passing an id. Either way, you should be able to given an id, calculate
the button that was pressed.
You can have the buttonGroup be a hidden widget and have the buttons
simply parented whereever you want, and thus just use the buttongroup as
the manager for the buttons, that way being able to connect a single
slot to any button that gets clicked.
Anyway, if it helps.
- Andrew Bushnell
Wido Depping wrote:
> On Monday 04 August 2003 23:40, Simon Edwards wrote:
>
>>On Monday 04 August 2003 23:30, Peter Clark wrote:
>>
>>> I've started dabbling with PyQt, but I'm a little confused as to how I
>>>can pass an argument to a function with a button click. For instance, the
>>>following doesn't work:
>>>(snip button code)
>>>
>>>self.connect(self.button1, SIGNAL("clicked()"),
>>
>>self.printMessage("Testing"))
>>
>>
>>>def printMessage(text):
>>> print text
>>
>>You can't. In this case printMessage()'s arguments must match clicked(),
>>which in PyQt would be:
>>
>>def printMessage(self): # don't forget the magic self.
>> print "foo"
>>
>>Why would you want to do this anyway? (You can use different slots for
>>different buttons...)
>
>
> There are some situations, where you have many buttons (perhaps dynamicly
> created), where you want to know who is the sender. It would be ugly, if you
> have to create a slot for every button during runtime.
> Instead you can install an eventfilter for every button. This filter gets the
> reference of the sender. This you way can get information which button was
> clicked. Especially if have chosen a unique name for every button.
> If someone is interested I can post some code.
>
> bye
> Wido
>
>
> _______________________________________________
> PyKDE mailing list PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
>
--
************************************
Andrew Bushnell
Senior Development Engineer
Fluent Inc.
10 Cavendish Court
Centerra Resource Park
Lebanon, NH 03766
awb at fluent.com
Phone: 603-643-2600, ext. 757
Fax: 603-643-1721
www.fluent.com
************************************
More information about the PyQt
mailing list