Delay time in stylesheet loading
-
wrote on 28 Jan 2014, 09:42 last edited by
Hi everyone,
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().
-
wrote on 28 Jan 2014, 10:20 last edited by
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:
@
QMainWindow {
background-color:red;
}
@ -
wrote on 28 Jan 2014, 10:42 last edited by
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. -
Try this:
@
// in main.cpp
QTimer::singleShot(800, mainWindowPointer, SLOT(show()));
return a.exec();
@It should delay the showing of your mainWindow for 800 ms.
-
wrote on 28 Jan 2014, 11:13 last edited by
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...
-
wrote on 28 Jan 2014, 11:18 last edited by
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.
1/9