Files
eUi/src/launcher/GUI/uiModule/components/pieWidget.h
T
RCiRoot bf8914d4a4 V20260131-2.3.13
增加额外存储NG图片和数据清零的功能。
2026-01-31 13:31:27 +08:00

62 lines
1.7 KiB
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.
#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QGridLayout>
#include <qpainter.h>
class PieWidget : public QWidget {
Q_OBJECT
public:
explicit PieWidget(QSize size,QWidget* parent = nullptr) : QWidget(parent) {
goodRate = 1.0; // Ĭ��100%��Ʒ��
hasData = true;
this->setFixedSize(size);
}
void setGoodRate(double rate) {
goodRate = qBound(0.0, rate, 1.0);
hasData = true;
update();
}
void setGoodRate(double rate, bool hasDataValue) {
goodRate = qBound(0.0, rate, 1.0);
hasData = hasDataValue;
update();
}
protected:
void paintEvent(QPaintEvent* event) override {
Q_UNUSED(event);
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
int size = qMin(width(), height()) - 10;
QRect rect((width() - size) / 2, (height() - size) / 2, size, size);
if (!hasData) {
p.setBrush(QColor(90, 90, 90));
p.setPen(Qt::NoPen);
p.drawEllipse(rect);
} else {
// ������Ʒ��ɫ����
p.setBrush(Qt::green);
p.setPen(Qt::NoPen);
int start = 1440;
p.drawPie(rect, start, int(goodRate * 360 * 16));
// ����ʣ�ಿ�֣���ѡ�������������Ҫ��ʾ��
p.setBrush(Qt::red);
p.drawPie(rect, start, int(-(1 - goodRate) * 360 * 16));
// ���ư�ɫ�ָ���
p.setPen(QPen(Qt::white, 2));
p.drawLine(rect.center(),
QPoint(rect.center().x(), rect.top()));
}
}
private:
double goodRate;
bool hasData;
};
#pragma once