// MyDialog.h //
#pragma once
#include <QProgressDialog>
#include <QString>
#include <QWidget>
class MyDialog : public QProgressDialog {
Q_OBJECT
public:
explicit MyDialog(const QString &text, QWidget *parent = nullptr) : QProgressDialog(text, nullptr, 0, 0, parent) {
qDebug() << "MyDialog()!";
}
virtual ~MyDialog() override {
qDebug() << "~MyDialog()!";
}
};
// main.cpp //
#include "MyDialog.h"
#include <QApplication>
const char *qss =
"MyDialog {"
"min-width: 260px; background-color: peachpuff;" // qss line 1
"}"
"MyDialog QLabel {"
"font-size: 16px; color: red;" // qss line 2
"}"
"MyDialog QProgressBar {"
"text-align: center; border-radius: 12px; border: 1px solid grey;" // qss line 3
"}";
int main(int argc, char **argv) {
QApplication qApp(argc, argv);
qApp.setStyleSheet(qss); // 1、set qss in QApplication instance(only). (like image1 below)
MyDialog dlg("Loading, Please wait...");
//dlg.setStyleSheet(qss); // 2、set qss in MyDialog instance(only). (like image2 below)
dlg.show();
return qApp.exec();
}
image1, where QSS is applied on QApplication
instance:
iamge2, where QSS is applied on MyDialog
instance:
When I set QSS to QApplication
instance,only "qss line 1" works.
When I set QSS to MyDialog
instance,all 3 QSS lines work.
Why? Is there a bug with my code or with Qt framework?
How to make all three lines of QSS code work when I use: qApp.setStyleSheet(qss)
?
Environment:
- Windows 10(1809)
- Qt 6.5.2(MSVC 2019 64-bit)
- CMake 3.27.1
- Ninja 1.11.1