PDA

View Full Version : how to add two lineEdit in the same gridlayout on checked of radio button



rahulgogoi
6th June 2011, 08:11
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,SLO T(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

Santosh Reddy
6th June 2011, 08:21
There is probably only one grid layout, This is the better way to do


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

pEditPassEnable=new QLineEdit(this);
pEditPassDisable=new QLineEdit(this);

pEditPassEnable->setText("Click to change Password");
pEditPassEnable->setEnabled(true);
pEditPassEnable->setStyleSheet("Color:rgb(255, 255, 255);");
pEditPassEnable->setStyleSheet("background-color: rgb(206, 218, 214);");

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(pEditPassEnable);
ui->PassgridLayout->addWidget(pEditPassDisable);

pEditPassEnable->hide();
pEditPassDisable->hide();

connect(ui->passwordRadiobutton,SIGNAL(toggled(bool)),this,SL OT(onCheckRadioButton(bool)));
}

bool SettingForm:nCheckRadioButton(bool checked)
{


if(checked)
{
pEditPassEnable->show();
pEditPassDisable->hide();
}
else if(!checked)
{
pEditPassEnable->hide();
pEditPassDisable->show();
}
return true;
}

moreover return value of the slot is ignored so there is no use of returning bool (from SettingForm:nCheckRadioButton()), unless you are using this function to for direct call else were

rahulgogoi
6th June 2011, 09:40
Thanks reddy

its working fine..

regards
Rahul