自检页面调试完成

This commit is contained in:
xu
2026-09-10 14:10:40 +08:00
parent 0baf228c67
commit 32878a9a80
34 changed files with 595 additions and 1568 deletions
+14 -2
View File
@@ -1,8 +1,19 @@
#include "ledindicator.h"
#include <QPainter>
#include <QRadialGradient>
#include <QFontMetrics>
#include "global.h"
QSize LedIndicator::sizeHint() const
{
QFont f = font();
f.setPixelSize(m_textPx);
const QFontMetrics fm(f);
// 宽度 = 文字起点(圆点区 + 左侧 10px) + 文字宽度 + 右侧 10px
const int w = textLeft() + fm.horizontalAdvance(m_text) + 10;
return QSize(w, 52); // 高度与构造函数 setFixedHeight(52) 一致
}
LedIndicator::LedIndicator(const QString& text, QWidget* parent)
: QWidget(parent), m_text(text)
{
@@ -35,6 +46,7 @@ void LedIndicator::setState(State s)
void LedIndicator::setText(const QString& t)
{
m_text = t;
updateGeometry(); // 文字变了,重新按新宽度请求布局
update();
}
@@ -84,8 +96,8 @@ void LedIndicator::paintEvent(QPaintEvent*)
// 文字
p.setPen(QColor(C::TEXT));
QFont f = p.font();
f.setPixelSize(24);
f.setPixelSize(m_textPx);
p.setFont(f);
const QRectF textRect(m_radius * 2 + 16, 0, width() - m_radius * 2 - 16, height());
const QRectF textRect(textLeft(), 0, width() - textLeft() - 10, height());
p.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, m_text);
}