How to add two lineEdit in the same gridlayout on checked of radio button



  • hello friends

    Actually i have two lineEdit,one gridlayout and a radio button..what i want to do is on checked of radio button i want to put my first LineEdit in the grid layout..and on unchecked of radio button i want to put my second lineEdit in gridlayout..but when i exexute my code..both my lineEdit is palced in two gridlayout..althoug there is only one gridlayout....the code i have wrriten is....

    @SettingForm::SettingForm(QWidget *parent) :QDialog(parent),ui(new Ui::SettingForm)
    {
    ui->setupUi(this);

      pEditPassEnable=new QLineEdit;
    
      pEditPassDisable=new QLineEdit;
    
    connect(ui->passwordRadiobutton,SIGNAL(toggled(bool)),this,SLOT(onCheckRadioButton(bool)));
    

    }
    @

    @bool SettingForm::onCheckRadioButton(bool checked)
    {

    if(checked)
    {
    
        pEditPassEnable->setText("Click to change Password");
    
        pEditPassEnable->setEnabled(true);
    
        pEditPassEnable->setStyleSheet("Color:rgb(255, 255, 255);");
    
        pEditPassEnable->setStyleSheet("background-color: rgb(206, 218, 214);");
    
        ui->PassgridLayout->addWidget(pEditPassEnable);
    }
    else if(!checked)
    {
    
        pEditPassDisable->setEchoMode(QLineEdit::Normal);
    
        pEditPassDisable->setText("Set Password");
    
        pEditPassDisable->setEnabled(false);
    
        pEditPassDisable->setStyleSheet("Color:rgb(128, 128, 128);");
    
        pEditPassDisable->setStyleSheet("background-color: rgb(206, 218, 214);");
    
        ui->PassgridLayout->addWidget(pEditPassDisable);
    }
    return true;
    

    }@

    can anyone please suggest me what mistake i have done in my code

    regards
    Rahul


  • Moderators

    your routine onCheckRadioButton is only executed on the toggled() signal.
    You need to define the visibility somewherelese, presumably your constructor.



  • I think you should do all the intializations in the constructor:

    • setting text and styles etc
    • adding to layout
    • hiding them by default (if this is what you want)

    and then just change the visibility of the labels using show()/hide() in onCheckRadioButton().



  • thanks all..

    its working now..

    regards
    Rahul


Log in to reply
 

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