logindlg::logindlg(QWidget *parent) : QDialog(parent) { islogin = false;//islogin在对话框初始化的时候值为false label0 = new QLabel; label0->setText(tr("用户名")); label1 = new QLabel; label1->setText(tr("密码")); label2 = new QLabel; label2->setText(tr("数据库名称")); label3 = new QLabel; label3->setText(tr("服务器IP")); lineEditUserID = new QLineEdit; lineEditPasswd = new QLineEdit; lineEditPasswd->setEchoMode(QLineEdit::Password);//设置为密码框 lineEdtDBName = new QLineEdit; lineEditHostIP = new QLineEdit; loginBtn = new QPushButton; loginBtn->setText(tr("登录")); logoutBtn = new QPushButton; logoutBtn->setText(tr("取消")); QGridLayout *layout1 = new QGridLayout(this);//构造函数需要写this layout1->addWidget(label0, 0, 0); layout1->addWidget(lineEditUserID, 0, 1); layout1->addWidget(label1, 1, 0); layout1->addWidget(lineEditPasswd, 1, 1); layout1->addWidget(label2, 2, 0); layout1->addWidget(lineEdtDBName, 2, 1); layout1->addWidget(label3, 3, 0); layout1->addWidget(lineEditHostIP, 3, 1); layout1->addWidget(loginBtn, 4, 0); layout1->addWidget(logoutBtn, 4, 1); layout1->setColumnStretch(0, 1);//设置0列 layout1->setColumnStretch(1, 1);//设置1列 layout1->setMargin(15);//设置layout边距 layout1->setSpacing(10);//设置layout当中控件与控件之间的间距 setWindowTitle(tr("登录")); //设置背景图片 this->setAutoFillBackground(true); QPalette palette; palette.setBrush(QPalette::Background, QBrush(QPixmap("2.jpg"))); setPalette(palette); connect(loginBtn, SIGNAL(clicked()), this, SLOT(loginBtnOnclick())); connect(logoutBtn, SIGNAL(clicked()), this, SLOT(logoutBtnOnclick())); }
loginDlg::loginDlg(QWidget *parent) : QDialog(parent) { lable0 = new QLabel; lable0->setText(tr("用户ID")); lineEditUserID = new QLineEdit; lable1 = new QLabel; lable1->setText(tr("密码")); lineEditPasswd = new QLineEdit; lineEditPasswd->setEchoMode(QLineEdit::Password);//设置为密码框 lable2 = new QLabel; lable2->setText(tr("服务器IP")); lineEditHostIP = new QLineEdit; lable3 = new QLabel; lable3->setText(tr("服务器端口号")); lineEditHostport = new QLineEdit; loginBtn = new QPushButton; loginBtn->setText(tr("登录")); logoutBtn = new QPushButton; logoutBtn->setText(tr("取消")); QGridLayout *layout1 = new QGridLayout(this); layout1->addWidget(lable0, 0, 0); layout1->addWidget(lineEditUserID, 0, 1); layout1->addWidget(lable1, 1, 0); layout1->addWidget(lineEditPasswd, 1, 1); layout1->addWidget(lable2, 2, 0); layout1->addWidget(lineEditHostIP, 2, 1); layout1->addWidget(lable3, 3, 0); layout1->addWidget(lineEditHostport, 3, 1); layout1->addWidget(loginBtn, 4, 0); layout1->addWidget(logoutBtn, 4, 1); layout1->setColumnStretch(0, 1); layout1->setColumnStretch(1, 1); layout1->setMargin(15); layout1->setSpacing(10); layout1->setSizeConstraint(QLayout::SetFixedSize); connect(loginBtn,SIGNAL(clicked()), this, SLOT(loginBtnOnclick())); connect(logoutBtn,SIGNAL(clicked()), this, SLOT(logoutBtnOnclick())); islogin = false; setWindowIcon(QPixmap(":/images/3.png"));//设置窗口图标 lineEditUserID->setFocus();//设置lineEditUserID控件具有输入焦点 //设置窗口没有边框 setWindowFlags(Qt::FramelessWindowHint); //设置对话框背景颜色或图片 setAutoFillBackground(true); QPalette palette; //palette.setColor(QPalette::Background, QColor(Qt::blue)); palette.setBrush(QPalette::Background, QBrush(QImage(":/images/1.jpg"))); setPalette(palette); }