[QT] 登录用户名和密码推荐设置代码

已测试通过,套用到自己代码在稍微修改一下就可以用,效果如下:
[QT] 登录用户名和密码推荐设置代码_第1张图片
鼠标放在登录按钮上之后:
[QT] 登录用户名和密码推荐设置代码_第2张图片
代码如下:

标题:
void LogonScreen::addLogTitleName()
{
m_pLoginAccount = new QLabel(this);
m_pLoginAccount->setGeometry(480, 50, 100, 40);
m_pLoginAccount->setText(“账户登录”);
m_pLoginAccount->setStyleSheet(“font: bold 20px; color:white”);
}

用户名:
void LogonScreen::addUserNameInfo()
{
m_pUserName = new QLabel(this);
m_pUserName->move(415, 120);
m_pUserName->setFixedSize(35, 35);
QPixmap pixmapa(":/resource/login/login_account.png");
m_pUserName->setPixmap(pixmapa);
m_pUserName->setStyleSheet(“font-size:20px”);
m_pUserName->setScaledContents(true);
m_pUserName->show();

m_pUserNameText    = new QLineEdit(this);
m_pUserNameText->move(450, 120);
m_pUserNameText->setFixedSize(115, 35);
m_pUserNameText->setPlaceholderText("请输入用户名");
m_pUserNameText->setStyleSheet("border:0px;border-style:outset;padding:0px;margin:0px;font:14px Arial;background:transparent;border-width:0; color: white");

m_pUserNameText->setFocus();

QRegExp regx("[1-9][0-9]{5}");
QValidator *validator = new QRegExpValidator(regx, this);
m_pUserNameText->setValidator(validator);

m_pHUserNameLine = new QFrame(this);
m_pHUserNameLine->setFrameStyle(QFrame::HLine | QFrame::Plain);
m_pHUserNameLine->setLineWidth(1);
m_pHUserNameLine->setGeometry(415, 156, 220, 1);
m_pHUserNameLine->setStyleSheet("color: white");

}

密码:
void LogonScreen::addPasswordInfo()
{
m_pUserPaswd = new QLabel(this);
m_pUserPaswd->move(415, 180);
m_pUserPaswd->setFixedSize(35, 35);
QPixmap pixmapb(":/resource/login/login_password.png");
m_pUserPaswd->setPixmap(pixmapb);
m_pUserPaswd->setScaledContents(true);
m_pUserPaswd->setStyleSheet(“font-size:20px”);
m_pUserPaswd->show();

m_pUserPaswdText    = new QLineEdit(this);
m_pUserPaswdText->move(450, 180);
m_pUserPaswdText->setFixedSize(185, 35);
m_pUserPaswdText->setPlaceholderText("请输入密码");
m_pUserPaswdText->setStyleSheet("border:0px;border-style:outset;padding:0px;margin:0px;font:14px Arial;background:transparent;border-width:0;color: white");
m_pUserPaswdText->setEchoMode(QLineEdit::Password);

m_pHPassWardLine = new QFrame(this);
m_pHPassWardLine->setFrameStyle(QFrame::HLine | QFrame::Plain);
m_pHPassWardLine->setLineWidth(1);
m_pHPassWardLine->setGeometry(415, 216, 220, 1);
m_pHPassWardLine->setStyleSheet("color: white");

}

登录按钮:
void LogonScreen::addLoginBtn()
{
m_pLoginButton = new QPushButton(this);
m_pLoginButton->setText(“登录”);
m_pLoginButton->setGeometry(415, 240, 220, 40);
m_pLoginButton->setStyleSheet(“QPushButton{border:1px solid gray;border-radius:5px;padding:2px 4px;font: bold 20px; background-color: white; color: rgb(72, 139, 231);}”
“QPushButton:hover{border:white}”
"QPushButton:hover{color:lightblue} "
“QPushButton:hover{background-color: rgb(25,63,114);}”
“QPushButton:pressed{background-color:rgb(85, 170, 255); }”); //设置圆角

connect (m_pLoginButton,SIGNAL(clicked(bool)),SLOT(slot_login()));

}

你可能感兴趣的:(QT)