qt设计一个简单的注册登录界面

qt设计一个简单的注册登录界面_第1张图片
qt设计一个简单的注册登录界面_第2张图片

实现代码:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setGeometry(550, 180, 300, 250);
    lineEdit = new QLineEdit(this);
    lineEdit->setGeometry(110, 55, 140, 20);
    lineEdit1 = new QLineEdit(this);
    lineEdit1->setGeometry(110, 80, 140, 20);
    lineEdit2 = new QLineEdit(this);
    lineEdit2->setGeometry(110, 105, 140, 20);
    lineEdit1->setEchoMode(QLineEdit::Password);
    lineEdit2->setEchoMode(QLineEdit::Password);
    pushButton = new QPushButton(this);
    pushButton->setGeometry(50, 130, 200, 20);
    pushButton->setText("添加详细信息");

    label = new QLabel(this);
    label->setGeometry(60, 55, 40, 20);
    label->setText("账号:");

    label1 = new QLabel(this);
    label1->setGeometry(60, 80, 40, 20);
    label1->setText("密码:");

    label2 = new QLabel(this);
    label2->setGeometry(35, 105, 60, 20);
    label2->setText("确认密码:");

    label3 = new QLabel(this);
    label3->setGeometry(0, 0, 0, 0);
    label4 = new QLabel(this);
    label4->setGeometry(0, 0, 0, 0);

    /* 实例化对象 */
    comboBox = new QComboBox(this);

    pushButton1 = new QPushButton(this);
    comboBox->setGeometry(0, 0, 0, 0);
    pushButton1->setGeometry(0, 0, 0,0);

    spinBox = new QSpinBox(this);
    spinBox->setGeometry(0, 0, 0, 0);

    /* 信号槽连接 */

    connect(pushButton,SIGNAL(clicked()), this,
    SLOT(pushButtonClicked()));


    connect(pushButton1,SIGNAL(clicked()), this,
    SLOT(pushButtonClicked1()));


    MBox.setWindowTitle("");
    MBox.setText("账号:");

    agreeBut = MBox.addButton("同意", QMessageBox::AcceptRole);
    connect(agreeBut,SIGNAL(clicked()), this,
    SLOT(pushButtonClicked2()));


}
MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::pushButtonClicked()
{
    if(flag==0)
    {
    if(QString::compare(lineEdit2->text() ,lineEdit1->text())==0)
    {
    this->setGeometry(550, 180, 300, 350);


    label3->setGeometry(60, 190, 40, 20);
    label3->setText("性别:");

    label4->setGeometry(60, 215, 40, 20);
    label4->setText("年龄:");

    pushButton1->setGeometry(50, 240, 200, 20);
    pushButton1->setText("注册");

    /* 设置 comboBox 的显示位置与大小 */
    comboBox->setGeometry(110, 190, 80, 20);

    /* 添加项,我们添加三个省份,作为 comboBox 的三个选项 */
    comboBox->addItem("男");
    comboBox->addItem("女");
    spinBox->setGeometry(110, 215, 80, 20);
    /* 设置范围 0~100 */
    spinBox->setRange(0, 100);

    /* 设置步长为 10 */
    spinBox->setSingleStep(1);

    /* 设置初始值为 100 */
    spinBox->setValue(0);

    a = lineEdit->text();
    b = lineEdit1->text();
    c = lineEdit2->text();
    d = comboBox->currentText();
    e = spinBox->text();
    flag++;

    }
    else
    {

        QMessageBox msgBox;
        int ret = QMessageBox::warning(this, tr("My Application"),
                                       tr("密码两次输入错误"),
                                        QMessageBox::Cancel,
                                       QMessageBox::Cancel);



    }
    }
    else
    {
        qDebug()<<lineEdit->text();
        qDebug()<<lineEdit1->text();
        qDebug()<<a;
        qDebug()<<b;
        if((QString::compare(lineEdit->text() ,a)==0) && (QString::compare(lineEdit1->text() ,b)==0))
        {
            a1 = lineEdit->text();
            b1 = lineEdit1->text();
            agreeBut1 = MBox1.addButton("登录成功", QMessageBox::AcceptRole);
            MBox1.exec();

        }
        else
        {
            QMessageBox msgBox1;
            int ret1 = QMessageBox::warning(this, tr("My Application"),
                                           tr("登录失败"),
                                            QMessageBox::Cancel,
                                           QMessageBox::Cancel);
        }
    }
}

void MainWindow::pushButtonClicked1()
{
    a = lineEdit->text();
    b = lineEdit1->text();
    c = lineEdit2->text();
    d = comboBox->currentText();
    e = spinBox->text();

    QString a1;

    a1.prepend(e);
    a1.prepend(" 年龄:");
    a1.prepend(d);
    a1.prepend(" 性别:");
     a1.prepend(a);
    a1.prepend("账户:");
    qDebug()<<a1;
        MBox.setText(a1);
        MBox.exec();





}
void MainWindow::pushButtonClicked2()
{
    delete label3;
    delete label4 ;
    delete pushButton1 ;
    delete comboBox;
    delete spinBox;
    delete label2;
    delete lineEdit2;
    this->setGeometry(550, 180, 300, 250);
  //  lineEdit = new QLineEdit(this);
   // lineEdit->setGeometry(110, 55, 140, 20);
  //  lineEdit1 = new QLineEdit(this);
  //  lineEdit1->setGeometry(110, 80, 140, 20);
    pushButton->setText("登录");

    label = new QLabel(this);
    label->setGeometry(60, 55, 40, 20);
    label->setText("账号:");

    label1 = new QLabel(this);
    label1->setGeometry(60, 80, 40, 20);
    label1->setText("密码:");


    label3 = new QLabel(this);
    label3->setGeometry(0, 0, 0, 0);
    label4 = new QLabel(this);
    label4->setGeometry(0, 0, 0, 0);

    /* 实例化对象 */
    comboBox = new QComboBox(this);

    pushButton1 = new QPushButton(this);
    comboBox->setGeometry(0, 0, 0, 0);
    pushButton1->setGeometry(0, 0, 0,0);

    spinBox = new QSpinBox(this);
    spinBox->setGeometry(0, 0, 0, 0);

}

你可能感兴趣的:(qt,ui,开发语言)