调整开机登录页面、数字键盘

This commit is contained in:
xu
2026-09-09 21:57:25 +08:00
parent bc17390d83
commit 7650e2983d
20 changed files with 17820 additions and 626 deletions
+55 -28
View File
@@ -1,5 +1,6 @@
#include "bootpassword.h"
#include "numpaddialog.h"
#include <QKeyEvent>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLineEdit>
@@ -16,64 +17,77 @@ BootPasswordPage::BootPasswordPage(AppContext* ctx, QWidget* parent)
root->addStretch(1);
QWidget* col = new QWidget(this);
col->setFixedWidth(800);
col->setFixedWidth(600);
col->setProperty("card", true); // 登录主体框体背景(面板色 + 圆角边框)
QVBoxLayout* lay = new QVBoxLayout(col);
lay->setSpacing(24);
lay->setContentsMargins(40, 40, 40, 40); // 框体内边距
lay->setSpacing(50);
lay->setAlignment(Qt::AlignHCenter);
// 品牌区
QLabel* brand = label("“玉兔”工业无线遥控器", 32, C::TEXT, true, col);
brand->setAlignment(Qt::AlignCenter);
QLabel* model = label("YTZT6K8EART2-aL25", 20, C::TEXT_SUB, false, col);
model->setAlignment(Qt::AlignCenter);
lay->addWidget(brand);
lay->addWidget(model);
lay->addSpacing(20);
// 标题
QLabel* title = label("请输入开机密码", 28, C::TEXT, true, col);
QLabel* title = label("请输入开机密码", 60, C::TEXT, true, col);
title->setAlignment(Qt::AlignCenter);
lay->addWidget(title);
lay->addSpacing(30);
// 密码输入框(只读回显,点击弹出数字键盘)
m_input = new QLineEdit(col);
m_input->setReadOnly(true);
m_input->setEchoMode(QLineEdit::Password);
m_input->setAlignment(Qt::AlignCenter);
m_input->setFixedSize(400, 88);
m_input->setPlaceholderText("点击输入密码");
m_input->setFixedSize(450, 120);
m_input->setStyleSheet("font-size:80px");
m_input->setProperty("clickable", true);
lay->addWidget(m_input, 0, Qt::AlignHCenter);
lay->addSpacing(40);
m_input->installEventFilter(this);
m_input->setFocusPolicy(Qt::NoFocus);
m_input->setFocusPolicy(Qt::StrongFocus);
// 错误提示(默认隐藏)
m_error = label("密码输入有误,请重新输入", 18, C::DANGER, true, col);
m_error = label("密码输入有误,请重新输入", 80, C::DANGER, true, col);
m_error->setAlignment(Qt::AlignCenter);
m_error->setStyleSheet("font-size:80px");
m_error->hide();
lay->addWidget(m_error);
// 确认 / 取消
QHBoxLayout* btnRow = new QHBoxLayout();
btnRow->setSpacing(40);
btnRow->setSpacing(80);
btnRow->addStretch(1);
QPushButton* ok = button("确认", "primary", col);
ok->setFixedSize(180, 72);
QPushButton* ok = button("确认", "", col);
ok->setFixedSize(160, 140);
ok->setStyleSheet("font-size:60px;");
connect(ok, &QPushButton::clicked, this, &BootPasswordPage::onConfirm);
QPushButton* cancel = button("取消", "", col);
cancel->setFixedSize(180, 72);
cancel->setFixedSize(160, 140);
// 取消语义:选中时红底白字(内联 :focus,确保覆盖全局蓝色选中态)
cancel->setStyleSheet("font-size:60px;QPushButton:focus{background-color:#E5484D;color:#FFFFFF;border:2px solid #FFA6A9;}");
connect(cancel, &QPushButton::clicked, this, &BootPasswordPage::onCancel);
btnRow->addWidget(ok);
btnRow->addWidget(cancel);
btnRow->addStretch(1);
lay->addLayout(btnRow);
// 忘记密码链接
QPushButton* forget = button("忘记密码/修改密码", "link", col);
forget->setFixedHeight(44);
forget->setCursor(Qt::PointingHandCursor);
// 忘记密码 / 修改密码(平时红字透明底,按下红底白字)
const QString linkBtnStyle =
"QPushButton{color:#E5484D;background:transparent;border:1px solid transparent;border-radius:6px;font-size:30px;}"
"QPushButton:hover,QPushButton:pressed,QPushButton:focus{background-color:#E5484D;color:#FFFFFF;border:1px solid #FFA6A9;}";
QHBoxLayout* forgetRow = new QHBoxLayout();
forgetRow->setSpacing(80);
forgetRow->addStretch(1);
QPushButton* forget = button("忘记密码", "", col);
forget->setFixedSize(130, 60);
forget->setStyleSheet(linkBtnStyle);
connect(forget, &QPushButton::clicked, this, &BootPasswordPage::onForget);
lay->addWidget(forget);
QPushButton* modify = button("修改密码", "", col);
modify->setFixedSize(130, 60);
modify->setStyleSheet(linkBtnStyle);
connect(modify, &QPushButton::clicked, this, &BootPasswordPage::onForget);
forgetRow->addWidget(forget);
forgetRow->addWidget(modify);
forgetRow->addStretch(1);
lay->addLayout(forgetRow);
root->addWidget(col, 0, Qt::AlignHCenter);
root->addStretch(1);
@@ -84,9 +98,18 @@ BootPasswordPage::BootPasswordPage(AppContext* ctx, QWidget* parent)
// 点击密码输入框 → 弹出数字键盘(拦截鼠标点击)
bool BootPasswordPage::eventFilter(QObject* obj, QEvent* ev)
{
if (obj == m_input && ev->type() == QEvent::MouseButtonPress) {
onInputClicked();
return true;
if (obj == m_input) {
if (ev->type() == QEvent::MouseButtonPress) {
onInputClicked();
return true;
}
if (ev->type() == QEvent::KeyPress) {
QKeyEvent* ke = static_cast<QKeyEvent*>(ev);
if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) {
onInputClicked();
return true;
}
}
}
return BasePage::eventFilter(obj, ev);
}
@@ -157,5 +180,9 @@ void BootPasswordPage::focusInput()
void BootPasswordPage::refreshInput()
{
m_input->setText(m_value);
const bool empty = m_value.isEmpty();
// 空态:无论是否被选中都显示提示文字(灰字);有内容:显示密码圆点
m_input->setEchoMode(empty ? QLineEdit::Normal : QLineEdit::Password);
m_input->setText(empty ? "点击输入密码" : m_value);
m_input->setStyleSheet(empty ? "font-size:50px;color:#9AA7B4;" : "font-size:80px;");
}
+1 -1
View File
@@ -41,7 +41,7 @@ PasswordMgmtPage::PasswordMgmtPage(AppContext* ctx, QWidget* parent)
// 确认 / 退出
QHBoxLayout* btnRow = new QHBoxLayout();
btnRow->addStretch(1);
QPushButton* ok = button("确认", "primary", col);
QPushButton* ok = button("确认", "", col);
ok->setFixedSize(180, 72);
connect(ok, &QPushButton::clicked, this, [this]() { emit navigate(PageReset); });
QPushButton* exit = button("退出", "", col);
+15 -5
View File
@@ -1,5 +1,6 @@
#include "passwordmgmtlogin.h"
#include "numpaddialog.h"
#include <QKeyEvent>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLineEdit>
@@ -33,7 +34,7 @@ PasswordMgmtLoginPage::PasswordMgmtLoginPage(AppContext* ctx, QWidget* parent)
m_input->setEchoMode(QLineEdit::Password);
m_input->setAlignment(Qt::AlignCenter);
m_input->setFixedSize(400, 88);
m_input->setFocusPolicy(Qt::NoFocus);
m_input->setFocusPolicy(Qt::StrongFocus);
m_input->installEventFilter(this);
lay->addWidget(m_input, 0, Qt::AlignHCenter);
@@ -44,7 +45,7 @@ PasswordMgmtLoginPage::PasswordMgmtLoginPage(AppContext* ctx, QWidget* parent)
QHBoxLayout* btnRow = new QHBoxLayout();
btnRow->addStretch(1);
QPushButton* ok = button("确认", "primary", col);
QPushButton* ok = button("确认", "", col);
ok->setFixedSize(180, 72);
connect(ok, &QPushButton::clicked, this, &PasswordMgmtLoginPage::onConfirm);
QPushButton* cancel = button("取消", "", col);
@@ -61,9 +62,18 @@ PasswordMgmtLoginPage::PasswordMgmtLoginPage(AppContext* ctx, QWidget* parent)
bool PasswordMgmtLoginPage::eventFilter(QObject* obj, QEvent* ev)
{
if (obj == m_input && ev->type() == QEvent::MouseButtonPress) {
onInputClicked();
return true;
if (obj == m_input) {
if (ev->type() == QEvent::MouseButtonPress) {
onInputClicked();
return true;
}
if (ev->type() == QEvent::KeyPress) {
QKeyEvent* ke = static_cast<QKeyEvent*>(ev);
if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) {
onInputClicked();
return true;
}
}
}
return BasePage::eventFilter(obj, ev);
}
+15 -5
View File
@@ -1,5 +1,6 @@
#include "passwordreset.h"
#include "numpaddialog.h"
#include <QKeyEvent>
#include "confirmdialog.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
@@ -30,7 +31,7 @@ PasswordResetPage::PasswordResetPage(AppContext* ctx, QWidget* parent)
m_input->setEchoMode(QLineEdit::Password);
m_input->setAlignment(Qt::AlignCenter);
m_input->setFixedSize(400, 88);
m_input->setFocusPolicy(Qt::NoFocus);
m_input->setFocusPolicy(Qt::StrongFocus);
m_input->installEventFilter(this);
lay->addWidget(m_input, 0, Qt::AlignHCenter);
@@ -40,7 +41,7 @@ PasswordResetPage::PasswordResetPage(AppContext* ctx, QWidget* parent)
QHBoxLayout* btnRow = new QHBoxLayout();
btnRow->addStretch(1);
QPushButton* ok = button("确认", "primary", col);
QPushButton* ok = button("确认", "", col);
ok->setFixedSize(160, 72);
connect(ok, &QPushButton::clicked, this, &PasswordResetPage::onConfirm);
QPushButton* cancel = button("取消", "", col);
@@ -61,9 +62,18 @@ PasswordResetPage::PasswordResetPage(AppContext* ctx, QWidget* parent)
bool PasswordResetPage::eventFilter(QObject* obj, QEvent* ev)
{
if (obj == m_input && ev->type() == QEvent::MouseButtonPress) {
onInputClicked();
return true;
if (obj == m_input) {
if (ev->type() == QEvent::MouseButtonPress) {
onInputClicked();
return true;
}
if (ev->type() == QEvent::KeyPress) {
QKeyEvent* ke = static_cast<QKeyEvent*>(ev);
if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) {
onInputClicked();
return true;
}
}
}
return BasePage::eventFilter(obj, ev);
}