Results 1 to 10 of 10

Thread: setchecked( true) of the radio button doesn't work

  1. #1
    Join Date
    Dec 2008
    Posts
    68

    Default setchecked( true) of the radio button doesn't work

    Hello,

    In the UI of my application, there are several radio buttons. They work well when I click them.

    However, when I use raidoButton_1->setChecked(true) to set them, UI doesn't change. Shall I call some other functions to update them?

    Thank you!

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: setchecked( true) of the radio button doesn't work

    Quote Originally Posted by richardander View Post
    However, when I use raidoButton_1->setChecked(true) to set them, UI doesn't change. Shall I call some other functions to update them?
    No, there is no need. It should work unless you block the event loop somehow. Do you have a busy loop in your application?
    J-P Nurmi

  3. #3
    Join Date
    Dec 2008
    Posts
    68

    Default Re: setchecked( true) of the radio button doesn't work

    There is no busy loop in the application.

    Could you let me know what are the commands/functions in QT that can block the event loop?

    Thank you!

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: setchecked( true) of the radio button doesn't work

    Does this work for you?
    Qt Code:
    1. // main.cpp
    2. #include <QtGui>
    3.  
    4. int main(int argc, char* argv[])
    5. {
    6. QApplication app(argc, argv);
    7. QRadioButton button1("checked");
    8. QRadioButton button2("unchecked");
    9. button1.setChecked(true);
    10. button2.setChecked(false);
    11. button1.show();
    12. button2.show();
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    Are you sure that the code where you change the check state gets actually executed?
    J-P Nurmi

  5. #5
    Join Date
    Dec 2008
    Posts
    68

    Default Re: setchecked( true) of the radio button doesn't work

    Hello,

    The code works. In fact, I did another test: put three radio buttons in one qgroupbox. Using setChecked( true) to select one radio button. But, if I want to clear the selection, the setChecked( false ) seems not working. In following code, first radio button is selected. But it can not be unselected.

    Qt Code:
    1. // main.cpp
    2. #include <QtGui>
    3.  
    4. int main(int argc, char* argv[])
    5. {
    6.  
    7. QApplication app(argc, argv);
    8.  
    9. QGroupBox *groupBox = new QGroupBox("Exclusive Radio Buttons");
    10.  
    11. QRadioButton *radio1 = new QRadioButton("&Radio button 1");
    12. QRadioButton *radio2 = new QRadioButton("R&adio button 2");
    13. QRadioButton *radio3 = new QRadioButton("Ra&dio button 3");
    14.  
    15.  
    16. QVBoxLayout *vbox = new QVBoxLayout;
    17. vbox->addWidget(radio1);
    18. vbox->addWidget(radio2);
    19. vbox->addWidget(radio3);
    20. vbox->addStretch(1);
    21. groupBox->setLayout(vbox);
    22.  
    23. groupBox->show();
    24.  
    25. radio1->setChecked(true);
    26.  
    27. radio1->setChecked(false);
    28.  
    29.  
    30. return app.exec();
    31. }
    To copy to clipboard, switch view to plain text mode 

    Is there any way to make no radiobutton selected?

    Thank you!

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setchecked( true) of the radio button doesn't work

    put needed radiobutons in QGroupBox.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Dec 2008
    Posts
    68

    Default Re: setchecked( true) of the radio button doesn't work

    As shown in the above sample code, the three radio buttons have been put in the QGroupBox so that only one radiobutton can be selected.

    however, if I want to clear the current selection and make all radiobutton unselected, what shall I do?

    thank you!

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setchecked( true) of the radio button doesn't work

    try to add the following code to yours
    Qt Code:
    1. ...
    2. radio1->setCheckable(false);
    3. radio2->setCheckable(false);
    4. radio3->setCheckable(false);
    5. ...
    To copy to clipboard, switch view to plain text mode 
    but in this case you can't be able to check buttons at all.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: setchecked( true) of the radio button doesn't work

    Radio buttons are "auto-exclusive" 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.
    J-P Nurmi

  10. #10
    Join Date
    Dec 2008
    Posts
    68

    Default Re: setchecked( true) of the radio button doesn't work

    Thank you!

Similar Threads

  1. Coloring of Radio Button
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 22nd July 2008, 15:05
  2. Undoing radio button checks.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2007, 09:12
  3. Paint XP radio button to pixmap
    By Ben.Hines in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2006, 21:15

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.