Code: Select all
#include
#include
#include
#include
#include
#include
class Test : public QWidget {
QProgressBar pb;
QLabel text;
QVBoxLayout layout{this};
public:
Test(): pb(this), text("Hello Wolrd", this) {
layout.addWidget(&text, 0, Qt::AlignCenter);
layout.addWidget(&pb);
pb.setMaximum(3600);
startTimer(50);
auto g = new QGraphicsDropShadowEffect;
g->setBlurRadius(10);
g->setOffset(0, 0);
g->setColor(Qt::white);
text.setGraphicsEffect(g);
text.setStyleSheet(
"font-size: 24px;"
"font-weight: bold;"
"color: rgb(66, 66, 66);"
);
pb.setTextVisible(false);
}
void timerEvent(QTimerEvent* event) override {
if (QDateTime::currentMSecsSinceEpoch() % 2)
pb.setValue(pb.value() + 1);
static int counter = 1;
text.setText(QString::number(counter++));
}
};
int main(int argc, char** argv) {
QApplication app(argc,argv);
Test t;
t.show();
return app.exec();
}
Ich bin mir sicher, dass das matchorientierte von Pb versucht habe, eine Klasse zu testen, und das Ergebnis ist tatsächlich ausgeführt und weiterhin ausgeführt und weiterhin ausgeführt wurde, und es wurde weiterhin ausgeführt.class ProgressBar : public QProgressBar {
public:
ProgressBar(QWidget* parent = nullptr): QProgressBar(parent) {}
void paintEvent(QPaintEvent* event) {
static int counter = 1;
QProgressBar::paintEvent(event);
qDebug()