Results 1 to 3 of 3

Thread: how to add two lineEdit in the same gridlayout on checked of radio button

  1. #1
    Join Date
    May 2011
    Posts
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60

    Default 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,SL OT(onCheckRadioButton(bool)));


    }
    bool SettingForm:nCheckRadioButton(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

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to add two lineEdit in the same gridlayout on checked of radio button

    There is probably only one grid layout, This is the better way to do

    Qt Code:
    1. ...
    2. SettingForm::SettingForm(QWidget *parent) :QDialog(parent),ui(new Ui::SettingForm)
    3. {
    4. ui->setupUi(this);
    5.  
    6. pEditPassEnable=new QLineEdit(this);
    7. pEditPassDisable=new QLineEdit(this);
    8.  
    9. pEditPassEnable->setText("Click to change Password");
    10. pEditPassEnable->setEnabled(true);
    11. pEditPassEnable->setStyleSheet("Color:rgb(255, 255, 255);");
    12. pEditPassEnable->setStyleSheet("background-color: rgb(206, 218, 214);");
    13.  
    14. pEditPassDisable->setEchoMode(QLineEdit::Normal);
    15. pEditPassDisable->setText("Set Password");
    16. pEditPassDisable->setEnabled(false);
    17. pEditPassDisable->setStyleSheet("Color:rgb(128, 128, 128);");
    18. pEditPassDisable->setStyleSheet("background-color: rgb(206, 218, 214);");
    19.  
    20. ui->PassgridLayout->addWidget(pEditPassEnable);
    21. ui->PassgridLayout->addWidget(pEditPassDisable);
    22.  
    23. pEditPassEnable->hide();
    24. pEditPassDisable->hide();
    25.  
    26. connect(ui->passwordRadiobutton,SIGNAL(toggled(bool)),this,SL OT(onCheckRadioButton(bool)));
    27. }
    28.  
    29. bool SettingForm:nCheckRadioButton(bool checked)
    30. {
    31.  
    32.  
    33. if(checked)
    34. {
    35. pEditPassEnable->show();
    36. pEditPassDisable->hide();
    37. }
    38. else if(!checked)
    39. {
    40. pEditPassEnable->hide();
    41. pEditPassDisable->show();
    42. }
    43. return true;
    44. }
    To copy to clipboard, switch view to plain text mode 

    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

  3. #3
    Join Date
    May 2011
    Posts
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60

    Default Re: how to add two lineEdit in the same gridlayout on checked of radio button

    Thanks reddy

    its working fine..

    regards
    Rahul

Similar Threads

  1. how to check radio button
    By tommy in forum Newbie
    Replies: 2
    Last Post: 24th February 2012, 03:50
  2. Replies: 3
    Last Post: 26th July 2010, 03:23
  3. Coloring of Radio Button
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 22nd July 2008, 16:05
  4. QTreeWidgetItem + radio Button
    By desch in forum Qt Programming
    Replies: 5
    Last Post: 14th November 2007, 15:15
  5. Undoing radio button checks.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2007, 10:12

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.