#include #include #include #include #include #include #include #include #include #include #include class fancyProcessBar : public QProgressBar { public: fancyProcessBar(QWidget* parent = nullptr) : QProgressBar(parent) {} protected: void paintEvent(QPaintEvent* event) override { Q_UNUSED(event); QPainter painter(this); QStyleOptionProgressBar option; initStyleOption(&option); // 自定义进度条外观 option.textVisible = false; // 隐藏进度文本 option.progress = value(); // 设置当前进度 option.maximum = maximum(); // 设置最大值 // 绘制进度条 style()->drawControl(QStyle::CE_ProgressBar, &option, &painter, this); } }; class FrequencyBar : public QWidget { public: FrequencyBar(QString titleIn) { title = titleIn; setMinimumSize(100, 60); } QSize sizeHint() const override { return QSize(100, 60); } void setProgress(double newProgress) { if (newProgress < 0.0) { progress = 0.0; } else if (newProgress > 1.0) { progress = 1.0; } else { progress = newProgress; } update(); // 重新绘制控件 } protected: void paintEvent(QPaintEvent* event) override { Q_UNUSED(event); QPainter painter(this); QRect rect = this->rect(); // Draw background //painter.fillRect(rect, Qt::darkGray); // Draw frequency text painter.setPen(Qt::white); painter.drawText(rect.adjusted(10, 10, -10, 10), Qt::AlignLeft | Qt::AlignTop, QString::number(minValue)); painter.drawText(rect.adjusted(10, 10, -10, 10), Qt::AlignHCenter | Qt::AlignTop, QString::number(minValue)); painter.drawText(rect.adjusted(10, 10, -10, 10), Qt::AlignRight | Qt::AlignTop, QString::number(maxValue)); painter.drawText(rect.adjusted(10, 30, -10, -10), Qt::AlignLeft | Qt::AlignTop, "min"); painter.drawText(rect.adjusted(10, 30, -10, -10), Qt::AlignHCenter | Qt::AlignTop, title); painter.drawText(rect.adjusted(10, 30, -10, -10), Qt::AlignRight | Qt::AlignTop, "Max"); int barWidth = rect.width() - 20; int barHeight = 5; QRect barRect(10, rect.height() / 2 - barHeight / 2-5, barWidth, barHeight); // Draw progress in the bar int progressWidth = static_cast(barRect.width() * progress); QRect progressRect(barRect.left(), barRect.top(), progressWidth, barHeight); QLinearGradient gradient(progressRect.left(), progressRect.top(), progressRect.right(), progressRect.bottom()); gradient.setColorAt(0.0, QColor("#F4A582")); gradient.setColorAt(1.0, QColor("#92C5DE")); painter.fillRect(progressRect, gradient); // Draw ticks int numTicks = 50; painter.setPen(Qt::white); for (int i = 0; i <= numTicks; ++i) { int x = barRect.left() + i * (barRect.width() / numTicks); painter.drawLine(x, barRect.top(), x, barRect.bottom()); } } private: QString title; int maxValue = CHAR_MAX,minValue=CHAR_MIN; int frequency =50; double progress; }; #pragma once