文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-619912.html
實(shí)現(xiàn)代碼:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-619912.html
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("添加詳細(xì)信息");
label = new QLabel(this);
label->setGeometry(60, 55, 40, 20);
label->setText("賬號(hào):");
label1 = new QLabel(this);
label1->setGeometry(60, 80, 40, 20);
label1->setText("密碼:");
label2 = new QLabel(this);
label2->setGeometry(35, 105, 60, 20);
label2->setText("確認(rèn)密碼:");
label3 = new QLabel(this);
label3->setGeometry(0, 0, 0, 0);
label4 = new QLabel(this);
label4->setGeometry(0, 0, 0, 0);
/* 實(shí)例化對(duì)象 */
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);
/* 信號(hào)槽連接 */
connect(pushButton,SIGNAL(clicked()), this,
SLOT(pushButtonClicked()));
connect(pushButton1,SIGNAL(clicked()), this,
SLOT(pushButtonClicked1()));
MBox.setWindowTitle("");
MBox.setText("賬號(hào):");
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("注冊(cè)");
/* 設(shè)置 comboBox 的顯示位置與大小 */
comboBox->setGeometry(110, 190, 80, 20);
/* 添加項(xiàng),我們添加三個(gè)省份,作為 comboBox 的三個(gè)選項(xiàng) */
comboBox->addItem("男");
comboBox->addItem("女");
spinBox->setGeometry(110, 215, 80, 20);
/* 設(shè)置范圍 0~100 */
spinBox->setRange(0, 100);
/* 設(shè)置步長(zhǎng)為 10 */
spinBox->setSingleStep(1);
/* 設(shè)置初始值為 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("密碼兩次輸入錯(cuò)誤"),
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("賬號(hào):");
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);
/* 實(shí)例化對(duì)象 */
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);
}
到了這里,關(guān)于qt設(shè)計(jì)一個(gè)簡(jiǎn)單的注冊(cè)登錄界面的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!