Add text when selecting radiobutton

  • When you select a specific radiobutton, you need to add text to the already existing one. Ie in the group box is 60, then 60 is added, if 40 is selected, then 40. How to do it correctly? Now my current text is deleted and replaced, but not added.
    An example of how it should be

  • Hi @fender ,
    You have to first check that radio button is checked or not for this,

    if( ui->radio_button->isChecked())
    code inside if condition is set the value of radio button( in your case 40 ,60 etc.) in lineEdit.
    This code help you.

  • Moderators

    @fender To append to the string

    ui->lineEdit->setText(ui->lineEdit->text() + ui->radio_button->text());

  • Qt Champions 2017

    Is that a good strategy adding the radios text ?
    How will you handle if user changes his mind and goes from 30 to 60 in group 2 ?
    However, if you construct the full string each time, it will work.
    Just wondering :)

  • @mrjj Yes you are right!!!!
    Whenever user changes radiobutton checked event then text is appending everytime cause of concatenation in lineEdit. Therefore button text is as it is everytime.

  • Lifetime Qt Champion


    Then re-build the full string when any of these widgets change and replace the whole text.

Log in to reply

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