how to query/test the state of a qt widget?

Diez B. Roggisch deets at nospam.web.de
Sun Jun 24 09:44:35 EDT 2007


raacampbell at gmail.com schrieb:
> Hi,
> 
> I'm writing a simple Python/Qt3 application and I am trying to write
> some code in which the user presses a button and the program performs
> action A or B depending upon the state of a pair of radio buttons. I
> would therefore like Python to read the state of the buttons. I was
> expecting this to be straightforward but I've not been able to work
> out how to do it and searching on Google hasn't helped. Surely there's
> a one-liner that will do what I want? It seems like an every-day sort
> of problem. I'm after something like:
> 
> if self.polPlotRadioButton.enabled==1: print "BLAH"
> 
> I've found squish from www.froglogic.com but that seems over the top.
> Possibly pythonqt.sourceforge.net has something that will solve my
> problem but that wants Qt4 and at the moment I'm making heavy use of
> matplotlib widgets and I've not worked out how to get them to
> incorporate into a Qt4 app so I'm stuck with Qt3.
> 
> Anyone know the answer?

RTFM. The Qt-docs are extensive. And the QRadioButton-docs are pretty 
straight forward:

http://doc.trolltech.com/3.3/qradiobutton.html#checked-prop



So your code above should be

if self.polPlotRadioButton.isChecked(): print "blah"

Diez



More information about the Python-list mailing list