Results 1 to 6 of 6

Thread: radiobutton output file

  1. #1
    Join Date
    Sep 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default radiobutton output file

    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-
    Last edited by nitriles; 18th September 2007 at 14:33.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: radiobutton output file

    Check who sent the signal using source() and then act accordingly.

  3. #3
    Join Date
    Sep 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: radiobutton output file

    Check where and what? Im not sure I understand what you mean.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: radiobutton output file

    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.

  5. The following user says thank you to marcel for this useful post:

    nitriles (20th September 2007)

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: radiobutton output file

    Quote Originally Posted by nitriles View Post
    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.

  7. #6
    Join Date
    Sep 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: radiobutton output file

    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!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.