Results 1 to 7 of 7

Thread: Not understand the class of QRadioButton very well!

  1. #1
    Join Date
    Jan 2011
    Posts
    40
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Not understand the class of QRadioButton very well!

    is the radiobutton checked false after the code
    Qt Code:
    1. ui->radioButton_2->setChecked(false);
    To copy to clipboard, switch view to plain text mode 
    every time i use the code above ,but the radiobutton could not being checked false after i clicked one radiobutton.I just don't know why the radiobutton could not be checked false again?Did I use the wrong class?

  2. #2
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Not understand the class of QRadioButton very well!

    is the radiobutton checked false after the code
    YES.

    why the radiobutton could not be checked false again?Did I use the wrong class?
    u r using the right class only. from where u r calling this code?

    check the doc:
    Radio buttons are autoExclusive by default. If auto-exclusive is enabled, radio buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. If you need multiple exclusive button groups for radio buttons that belong to the same parent widget, put them into a QButtonGroup.
    Bala
    Last edited by BalaQT; 24th January 2011 at 13:00.

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

    Default Re: Not understand the class of QRadioButton very well!

    Quote Originally Posted by BalaQT View Post
    YES.
    NO.

    u r using the right class only. from where u r calling this code?
    No, it's not the right class. If you want to be able to uncheck a button, use QCheckBox and not QRadioButton. You can make them non-exclusive but this effectively makes the button a check box.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jan 2011
    Posts
    40
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Not understand the class of QRadioButton very well!

    is the radiobutton checked false after the code
    Qt Code:
    1. ui->radioButton_2->setChecked(false);
    To copy to clipboard, switch view to plain text mode 
    every time i use the code above ,but the radiobutton could not being checked false after i clicked one radiobutton.I just don't know why the radiobutton could not be checked false again?Did I use the wrong class?

    I know the QButtonGroup and I enable the autoExclusive so that there is only one radiobutton could be checked true in the group.But I am wondering maybe I call this code in the wrong place.I use the QScrollBar ' signal valueChanged(int) to the ui->radiobutton->setChecked(false),once the value of the QScrollBar is changed ,the executive will call the code ui->radiobutton->setChecked(false).I was just thinking like this.Maybe I'm wrong.By the way ,is it the right way to use the QScrollBar ' signal valueChanged(int) what I just mentioned or not.Please give me some tips. My mother language is not english .So it is hard for me to read the doc.

  5. #5
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Not understand the class of QRadioButton very well!

    Please show more code and not just one line.

    Why don't you write some debug output to verify your assumtions:

    Qt Code:
    1. qDebug() << "[BEFORE]: Radio button is checked:" << ui->radioButton_2->isChecked();
    2. ui->radioButton_2->setChecked(false);
    3. qDebug() << "[AFTER]: Radio button is checked:" << ui->radioButton_2->isChecked();
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Not understand the class of QRadioButton very well!

    In general calling setChecked(false) on a radio button does nothing (unless you explicitly disable exclusivity). You need to call setChecked(true) on some other button to cause this button to be unchecked.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7

    Default Re: Not understand the class of QRadioButton very well!

    QRadioButton class is a radio button, which can be switched checked or unchecked. Typically, the radio buttons to show the user "one of many" choice. Group of radio buttons only one button at a time can be controlled if the user selects another button, the button selected above is turned off.

Similar Threads

  1. Something i am not understand about Qt.
    By HeX0R in forum Newbie
    Replies: 8
    Last Post: 12th February 2010, 04:37
  2. need help .not able to understand.......
    By sh123 in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2009, 01:50
  3. Unchecking QRadioButton
    By gruszczy in forum Qt Programming
    Replies: 3
    Last Post: 26th February 2008, 00:55
  4. QRadioButton
    By sonuani in forum Newbie
    Replies: 1
    Last Post: 20th February 2008, 09:30
  5. QRadioButton
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 8th October 2007, 07:25

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
  •  
Qt is a trademark of The Qt Company.