给我写一个QT的圆形进度条程序,并展示下效果
时间: 2024-05-10 07:20:48 浏览: 73
抱歉,我是AI语言模型,无法展示效果。以下是一个基于QT的圆形进度条程序,供您参考:
```
#include <QApplication>
#include <QWidget>
#include <QProgressBar>
#include <QHBoxLayout>
#include <QTimer>
#include <QPainter>
class CircleProgressBar : public QWidget
{
public:
CircleProgressBar(QWidget *parent = nullptr) : QWidget(parent)
{
m_percent = 0;
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(updatePercent()));
m_timer->start(50);
}
void setPercent(int percent)
{
m_percent = percent;
update();
}
protected:
void paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(255, 255, 255));
painter.drawRect(0, 0, width(), height());
painter.setBrush(QColor(200, 200, 200));
painter.drawEllipse(0, 0, width(), height());
painter.setBrush(QColor(0, 255, 0));
painter.drawPie(0, 0, width(), height(), 90 * 16, -m_percent * 16);
}
private slots:
void updatePercent()
{
m_percent++;
if (m_percent > 100) {
m_percent = 0;
}
update();
}
private:
int m_percent;
QTimer *m_timer;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *widget = new QWidget();
QHBoxLayout *layout = new QHBoxLayout(widget);
CircleProgressBar *progressbar = new CircleProgressBar();
layout->addWidget(progressbar);
widget->setFixedSize(200, 200);
widget->show();
return app.exec();
}
```
阅读全文