PDA

View Full Version : stylesheet loading issue - thread



talk2amulya
26th February 2009, 07:06
Hi All,

I have a very big stylesheet file and if i try to load the stylesheet in the main thread, it increases the application launch time by about 10-12 seconds which obviously is unacceptable. So, i tried to call setStyleSheet() from a different thread but that gives a run time error "cannot send events to objects created in a different thread" which is understandable..i cant even even call moveToThread() on qApp..so is there ANY alternate way of being able to set stylesheet of application from a different thread?

spirit
26th February 2009, 07:21
load css in work thread and then emit signal with this css data and apply it in main thread.
all GUI operations must be perfomed in main thread.

talk2amulya
26th February 2009, 07:26
yeh, i also thought about that..ok, one thing that might solve the issue..what could it be, reading the big file or implementation of setStyleSheet() thats taking a lot of time..if its reading the file, then the solution u gave will work..but i m having a feeling that its setStyleSheet() thats taking that much time..need some expert advice..

spirit
26th February 2009, 07:30
you can try to load css by parts: read settings for one object, e.g. QPushButton, apply this part, then adde processEvents, then read next object settings etc.

talk2amulya
26th February 2009, 07:39
yes, i've thought about it and we'll go about doing that in another phase..but right now we have to work this solution out..so any idea about what could be taking so long? my file currently has around 3600 lines..so is it file reading or setStyleSheet() thats taking hell of a time?

talk2amulya
26th February 2009, 07:59
i checked and its setStyleSheet() thats taking so much time..i guess there is no other way than to break it into smaller ones..thanks for ur replies!

Lykurg
26th February 2009, 10:19
Damn, 3600 lines CSS. You are crazy! :D
If you have such a big file you should really consider to write your own style. This would be faster than loading a 3600 line file... (Since I never ever had such a big file, can't you optimize it? I can't imagine for what you need 3600 lines.)

talk2amulya
26th February 2009, 11:26
its a big project and all styling of ALL widgets is done through ONE stylsheet..and believe me, considering the number of widgets we have, 3600 lines is nothing :) well, anyways, the management has woken up and wants us to find "better" solutions .. we've already suggested breaking down one stylesheet to a number of stylesheets per plugin..that will save a lot of time

Bjoern
26th February 2009, 12:53
To be honest, you shouldn't apply such a big stylesheet. :p

The mechanism when applying a stylesheet to a widget is that every child widget parses the whole thing (in fact a QString) to see what attributes its affected by, overriding the applications default style (not +"sheet").
Same happens for any child widget when being constructed after the stylesheet was applied.

So you should indeed split this file into a general part which gets set on the main window, and some special parts, which only affect some specific children.
Note that there's not necessary inheritance applied when doing this (you'll have to specify e.g. a global background color in EACH of your stylesheet files)

If that is not possible you'll have to redesign the entire stuff ... I wonder how much such a monstrous stylesheet would lock up a browser :eek:

That's definitely not the way stylesheets are intended to be used, even though I know about the advantages of having only one single file ;)