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

已测试通过,套用到自己代码在稍微修改一下就可以用,效果如下:
在这里插入图片描述
鼠标放在登录按钮上之后:
在这里插入图片描述
代码如下:

标题:
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()));

}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值