feat:初始化wuhan_QT界面代码
This commit is contained in:
+159
@@ -0,0 +1,159 @@
|
||||
#include "global.h"
|
||||
#include <QStyle>
|
||||
|
||||
// 启动 500ms 闪烁:每 500ms 切换一次动态属性,QSS 据此在 40%↔100% 透明度间切换
|
||||
QTimer* startBlink(QWidget* w, const char* prop)
|
||||
{
|
||||
// 复用已存在的定时器
|
||||
if (auto* t = w->findChild<QTimer*>(QString("blink_") + prop))
|
||||
return t;
|
||||
QTimer* t = new QTimer(w);
|
||||
t->setObjectName(QString("blink_") + prop);
|
||||
t->setInterval(500);
|
||||
QObject::connect(t, &QTimer::timeout, w, [w, prop]() {
|
||||
bool cur = w->property(prop).toBool();
|
||||
w->setProperty(prop, !cur);
|
||||
w->style()->unpolish(w);
|
||||
w->style()->polish(w);
|
||||
w->update();
|
||||
});
|
||||
w->setProperty(prop, true);
|
||||
t->start();
|
||||
return t;
|
||||
}
|
||||
|
||||
void stopBlink(QWidget* w, const char* prop)
|
||||
{
|
||||
if (auto* t = w->findChild<QTimer*>(QString("blink_") + prop)) {
|
||||
t->stop();
|
||||
delete t;
|
||||
}
|
||||
w->setProperty(prop, false);
|
||||
w->style()->unpolish(w);
|
||||
w->style()->polish(w);
|
||||
w->update();
|
||||
}
|
||||
|
||||
QString appStyleSheet()
|
||||
{
|
||||
const QString s = QString(R"QSS(
|
||||
* {
|
||||
font-family: "Microsoft YaHei", "PingFang SC", "Source Han Sans CN";
|
||||
outline: none;
|
||||
}
|
||||
QWidget {
|
||||
background-color: BG;
|
||||
color: TXT;
|
||||
}
|
||||
QWidget#pageRoot {
|
||||
background-color: BG;
|
||||
}
|
||||
QLabel {
|
||||
background: transparent;
|
||||
color: TXT;
|
||||
}
|
||||
QLabel[sub="true"] { color: SUB; }
|
||||
QLabel[title="true"] { color: TXT; font-weight: 700; }
|
||||
|
||||
/* ===== 按钮 ===== */
|
||||
QPushButton {
|
||||
background-color: PHI;
|
||||
color: TXT;
|
||||
border: 1px solid BD;
|
||||
border-radius: 12px;
|
||||
font-size: 22px;
|
||||
min-height: 56px;
|
||||
}
|
||||
QPushButton:hover { background-color: PRI; color: TXT; border-color: PRI; }
|
||||
QPushButton:pressed { background-color: PRI; color: #FFFFFF; border-color: PRI; }
|
||||
QPushButton:checked { background-color: PRI; color: #FFFFFF; border: none; }
|
||||
QPushButton:disabled { background-color: DIS; color: DIST; border-color: DIS; }
|
||||
|
||||
QPushButton[variant="primary"] { background-color: PRI; color: #FFFFFF; border: none; }
|
||||
QPushButton[variant="primary"]:disabled { background-color: DIS; color: DIST; }
|
||||
QPushButton[variant="danger"] { background-color: DAN; color: #FFFFFF; border: 1px solid DAN; border-radius: 6px; }
|
||||
QPushButton[variant="danger"]:disabled { background-color: DIS; color: DIST; border-color: DIS; }
|
||||
QPushButton[variant="link"] { background: transparent; color: PRI; border: none; font-size: 22px; }
|
||||
QPushButton[variant="estop"] {
|
||||
background-color: DAN; color: #FFFFFF; border: 1px solid DAN; border-radius: 6px; font-size: 24px; font-weight: 700;
|
||||
}
|
||||
|
||||
/* ===== 输入框 ===== */
|
||||
QLineEdit {
|
||||
background-color: BG;
|
||||
border: 2px solid BD;
|
||||
border-radius: 8px;
|
||||
color: TXT;
|
||||
font-size: 32px;
|
||||
padding: 0 12px;
|
||||
}
|
||||
QLineEdit:focus { border: 3px solid PRI; }
|
||||
|
||||
/* ===== 进度条 ===== */
|
||||
QProgressBar {
|
||||
background-color: PHI;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
text-align: center;
|
||||
color: #FFFFFF;
|
||||
font-size: 22px;
|
||||
}
|
||||
QProgressBar::chunk { background-color: PRI; border-radius: 4px; }
|
||||
|
||||
/* ===== 表格 ===== */
|
||||
QTableWidget {
|
||||
background-color: PAN;
|
||||
color: TXT;
|
||||
border: 1px solid BD;
|
||||
gridline-color: BD;
|
||||
font-size: 22px;
|
||||
alternate-background-color: #2A3442;
|
||||
}
|
||||
QHeaderView::section {
|
||||
background-color: PHI;
|
||||
color: TXT;
|
||||
border: none;
|
||||
border-right: 1px solid BD;
|
||||
border-bottom: 1px solid BD;
|
||||
padding: 8px;
|
||||
font-size: 22px;
|
||||
}
|
||||
QTableWidget::item { padding: 6px; }
|
||||
QTableWidget::item:selected { background-color: rgba(61,139,253,0.15); color: TXT; }
|
||||
|
||||
/* ===== 数字键盘 ===== */
|
||||
QPushButton[numpad="true"] {
|
||||
background-color: PHI; color: TXT; border: 1px solid BD; border-radius: 12px; font-size: 40px;
|
||||
}
|
||||
QPushButton[numpad="true"]:pressed { background-color: PRI; color: #FFFFFF; }
|
||||
|
||||
/* ===== 告警文字(红色闪烁由 blink 属性驱动) ===== */
|
||||
QLabel[alert="true"] { color: DAN; font-weight: 700; }
|
||||
QLabel[alert="true"][blink="false"] { color: rgba(229,72,77,102); }
|
||||
QLabel[amber="true"] { color: WAR; font-weight: 700; }
|
||||
|
||||
/* ===== 数据卡片 ===== */
|
||||
QWidget[card="true"] {
|
||||
background-color: PAN;
|
||||
border: 2px solid BD;
|
||||
border-radius: 12px;
|
||||
}
|
||||
QLabel[cardTitle="true"] { color: TXT; font-weight: 700; }
|
||||
)QSS");
|
||||
|
||||
// 用占位替换(注意:DIST 须在 DIS 之前替换,避免前缀误匹配)
|
||||
QString out = s;
|
||||
out.replace("DIST", C::DISABLED_T);
|
||||
out.replace("DIS", C::DISABLED);
|
||||
out.replace("BG", C::BG);
|
||||
out.replace("PAN", C::PANEL);
|
||||
out.replace("PHI", C::PANEL_HI);
|
||||
out.replace("BD", C::BORDER);
|
||||
out.replace("TXT", C::TEXT);
|
||||
out.replace("SUB", C::TEXT_SUB);
|
||||
out.replace("PRI", C::PRIMARY);
|
||||
out.replace("SUC", C::SUCCESS);
|
||||
out.replace("WAR", C::WARNING);
|
||||
out.replace("DAN", C::DANGER);
|
||||
return out;
|
||||
}
|
||||
Reference in New Issue
Block a user