PDA

View Full Version : radiobutton output file



nitriles
18th September 2007, 15:18
I created a form with Qt which has 2 radio buttons and a push button
button 1 has label cd
button 2 has label dvd
I want the user to choose one of the radio buttons and click the button which will write the text (cd or dvd) into my console when I run the program.
I managed to do this for a listbox:

listitem = str(self.lB_List.currentText())
if listitem == "hey":
print "hey"
elif listitem == "bye":
print "bye"
elif listitem == "ciao":
print "ciao"

but how can i do this for a radiogroup? I've searched the forum but can't find a clear answer.

Please help, thanks

-NITRILES-

wysota
18th September 2007, 16:39
Check who sent the signal using source() and then act accordingly.

nitriles
19th September 2007, 09:49
Check where and what? Im not sure I understand what you mean.

marcel
19th September 2007, 10:10
Add your tow radio buttons to a QButtonGroup and set their id's to 1 and 2, for example.

Now, when one of these buttons is clicked, the button group will emit the buttonClicked(int id) signal. The id will be 1 or 2, depending on which button was clicked.

You should connect the buttonClicked signal somewhere in your class and set a flag, for instance a boolean flag isCd, which can be true or false. Next, when you press the push button, you should look at isCd and print "cd" if it is true and "dvd" otherwise.

Another solution is to connect the clicked() signal of the pushbutton to s slot, and in that slot check the two radio buttons to see which one is checked. You can do this with QRadioButton::isChecked(). I think this one is easier.

wysota
19th September 2007, 11:24
Check where and what? Im not sure I understand what you mean.

Sorry, should be sender() :) Check inside the slot. sender() returns a pointer to the object that sent the signal.

nitriles
20th September 2007, 10:04
Thanks a lot to both!
Marcel thanks for explaining it in a user friendly language lol.
I finally managed to make it, its part of a bigger program and this was only a small example, but now atleast i can implement it.
THANKS!