Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Delay time in stylesheet loading
I made a simple application that should set a stylesheet loading settings from a file.
I put this->setStylesheet() in the MainWindow 's constructor, right after setupUI().
It happens that at first mainwindow shows itself plain, and after less than a second, modifications are applied.
This is an annoying graphic problem.
Set the stylesheet in your main.cpp, using QApplication::setStylesheet().
if I call a.setStylesheet("background-color:red;") for example, a Qt wanring "Could not parse application stylesheet" is displayed".
If you mean i have to call some static method QApplication::setStylesheet() the compiler stops.
No, I do not mean static methods. Try a more explicit QSS, like:
Yes it works, but no evident timing improvement.
It seems like if stylesheet modifications are processed after showevent...
In such a case I'd prefer waiting for stylesheet rendering and show the main window after this have happen.
But I don't know how.
// in main.cpp
QTimer::singleShot(800, mainWindowPointer, SLOT(show()));
It should delay the showing of your mainWindow for 800 ms.
That's funny, it waits 800ms, shows the plain white window, and change the stylesheet with evident time lapse.
Even if I change the stylesheet form the UI form the effect is the same, and I forgot to say, but it's obvious, that timing differences depends on the stylesheet type, it increase for gradients for example.
Mybe the sequence is that the stylesheet engine works after the show event...
I noticed that it has the same behaviour if I iconize the window and then I show it clicking on the icon.
It shows the plain window and then fill the stylesheet with time.
Maybe could be my PC extremly slow and this effetc emphasizes more than usual.
[quote author="ale82" date="1390907896"]Maybe could be my PC extremly slow and this effetc emphasizes more than usual.[/quote]
This could be the case. I have seen some really heavy QSS code that took up to 4 seconds to load... but it never exhibited the behaviour you have mentioned. In my case, the whole GUI was loading in the background and once it was shown, it already had the styling applied.