GroupBox problem



  • Hello. I've got a question about groupBox. I add 2 radioButtons, groupBox and label on form. I want to set text of the label when radioButton is checked. But I don't know how to use ui.groupBox to access the radiobutton's state.
    I will be glad for any help.
    Regards


  • Moderators

    The short answer is - you don't. Groupbox knows nothing about the radiobutton's state. Why would it?

    Assuming you have a radiobutton added in the designer you would connect a custom slot to it's toggled() signal and set your label content there.

    Example:

    @
    //somewhere in the MainWindow constructor
    connect(ui.radioButton, SIGNAL(toggled(bool)), this, SLOT(someSlot(bool)));

    //and in your custom slot:
    void MainWindow::someSlot(bool state)
    {
    if(state)
    ui.myLabel->setText("state 1");
    else
    ui.myLabel->setText("state 2");
    }
    @
    groupbox has basically nothing to do with it.



  • Thank you for your answer. I have to think about it and rewrite it in the way you wrote here.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.