Results 1 to 9 of 9

Thread: stylesheet loading issue - thread

  1. #1
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default stylesheet loading issue - thread

    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?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: stylesheet loading issue - thread

    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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: stylesheet loading issue - thread

    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..

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: stylesheet loading issue - thread

    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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: stylesheet loading issue - thread

    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?

  6. #6
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: stylesheet loading issue - thread

    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!

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: stylesheet loading issue - thread

    Damn, 3600 lines CSS. You are crazy!
    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.)

  8. #8
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: stylesheet loading issue - thread

    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

  9. #9
    Join Date
    May 2008
    Location
    duesseldorf, germany
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: stylesheet loading issue - thread

    To be honest, you shouldn't apply such a big stylesheet.

    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

    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

Similar Threads

  1. QLabel Stylesheet selector issue.
    By Enygma in forum Qt Programming
    Replies: 3
    Last Post: 24th August 2007, 14:52
  2. Stop the thread during recursivly loading directory
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2007, 19:02
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  4. Replies: 10
    Last Post: 20th March 2007, 22:19
  5. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.