Files
QT_wuhan_YT/widgets/ledindicator.h
T
2026-09-09 17:00:37 +08:00

36 lines
974 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef LEDINDICATOR_H
#define LEDINDICATOR_H
#include <QWidget>
#include <QTimer>
// ===================== 指示灯(自绘圆形渐变 + 外发光) =====================
// 状态:灰=未运行/关闭/正常,绿=运行/开启/到位,红=故障/液位低,
// 黄=检测中;红闪/黄闪按 500ms 周期闪烁(透明度 40%↔100%)。
class LedIndicator : public QWidget
{
Q_OBJECT
public:
enum State { Off, Green, Red, RedBlink, Yellow, YellowBlink };
explicit LedIndicator(const QString& text, QWidget* parent = nullptr);
void setState(State s);
void setText(const QString& t);
State state() const { return m_state; }
QSize sizeHint() const override { return QSize(140, 44); }
protected:
void paintEvent(QPaintEvent*) override;
private:
State m_state = Off;
QString m_text;
QTimer* m_blink = nullptr;
bool m_on = true;
int m_radius = 16; // 圆形指示点 32×32
};
#endif // LEDINDICATOR_H