Код: Выделить всё
#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);//If the number 1 is changed to a number greater than or equal to 20, it will work normally
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();
}
Я уверен, что Paintevent Pb был выполнен, потому что я пытался написать класс, чтобы проверить его, и результат в том, что он действительно был выполнен и продолжается выполнять постоянно.class ProgressBar : public QProgressBar {
public:
ProgressBar(QWidget* parent = nullptr): QProgressBar(parent) {}
void paintEvent(QPaintEvent* event) {
static int counter = 1;
QProgressBar::paintEvent(event);
qDebug()
Подробнее здесь: https://stackoverflow.com/questions/795 ... der-at-all
Мобильная версия