Results 1 to 11 of 11

Thread: Setting stylesheet for "almost" all widgets

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Setting stylesheet for "almost" all widgets

    Hi,

    I want to set my widgets' background color to black and text color to gray.
    Qt Code:
    1. qApp->setStyleSheet(QString("QWidget {background: black; color: gray;}
    To copy to clipboard, switch view to plain text mode 

    BUT...

    there are some widgets(about 4 or 5 classes) for which I do not want to set the new colors.

    How to exclude those classes?

    Thanks for any hint.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Setting stylesheet for "almost" all widgets

    How about setting explicitly an empty style sheet for those widgets to be excluded?
    J-P Nurmi

  3. The following 2 users say thank you to jpn for this useful post:

    maverick_pol (3rd April 2008), phillip_Qt (9th April 2008)

  4. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Setting stylesheet for "almost" all widgets

    Sounds good. Will try it.
    Will this work?
    Qt Code:
    1. qApp->setStyleSheets(QString("QWidget: { color: red}; MyClass: {color :blue};"));
    To copy to clipboard, switch view to plain text mode 
    I tried setting ' { } ' for one of the classes and this do not work.
    I also tried setting(just after qApp->...):
    Qt Code:
    1. myobject->setStyleSheet(QString(""));
    To copy to clipboard, switch view to plain text mode 
    Do not work as well.

    What do you mean by "empty style sheets"?

    Kacper
    Last edited by maverick_pol; 3rd April 2008 at 08:48.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Setting stylesheet for "almost" all widgets

    Yeah, an empty string was exactly what I had on my mind...
    J-P Nurmi

  6. #5
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Setting stylesheet for "almost" all widgets

    Ok, but this solution do not work.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  7. #6
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: Setting stylesheet for "almost" all widgets

    I have same behavior here:

    I am applying a general stylesheets for all widgets. But what i want is that for some kind of same widgets to have another style. So I applied a different stylesheet to those widgets and does not work... it just continue using the general applied stylesheet.

    A Clear Example: I have forms buttons on all over my app so i use a general stylesheet for all those buttons, but i have some buttons that i use for menus/toolbar/etc. that i wish to set a different style, but when i write the stylesheet for those buttons, it still continue using the one applied before. Why?

    Is this possible with Qt4?

    Cheers.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  8. #7
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting stylesheet for "almost" all widgets

    Quote Originally Posted by jpn View Post
    How about setting explicitly an empty style sheet for those widgets to be excluded?
    Hi.
    I ve same problem like u. Can u plz tell me how to set default style sheet?
    I tried like setStyleSheet(QString(""));
    But its not working. My code is as follows

    Qt Code:
    1. void NightColor()
    2. {
    3. ptr->LoadStyleSheet("Night");
    4.  
    5. }
    6. void DayColor()
    7. {
    8. setStyleSheet(QString(""));
    9.  
    10. }
    11.  
    12. void Toggle()
    13. {
    14. if(m_iFlag == 0)
    15. NightColor();
    16. else
    17. DayColor();
    18. }
    To copy to clipboard, switch view to plain text mode 

    I ve a push button. if i press it 1st time Nightcolor() ll b called. But if i ll press nxt time default style sheet shd be activated. but its not activating.
    Last edited by jpn; 9th April 2008 at 08:23. Reason: missing [code] tags
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  9. #8
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Setting stylesheet for "almost" all widgets

    hi,

    StyleSheets("");
    does nothing. It do not work as nothing is being done. Even the "default" style sheet should contain that "default" settings.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  10. #9
    Join Date
    Apr 2007
    Location
    United States
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Lightbulb Re: Setting stylesheet for "almost" all widgets

    In my app, I set a global style sheet for the entire app. For specific plugins I will set style sheets on them took look like I want. If you set an empty style sheet on a child widget, the parents style sheet will be applied. This is at least the behavior i see with Qt 4.4. I use this to set a style on say a button when an event happens and when the user acknowledges the button by clicking on it, i will set the style sheet to empty to set the look an feel back to that of the parent.

    I would suggest that for a quick fix, just explicitly name the objects you want to apply the style sheet to instead of applying it globally. You can also apply the style sheet globally but you will have to specifically set a style sheet for those objects you want to appear different. You can't just set it to empty.

    ex:
    #ObjectName1 QWidget,
    #ObjectName2 QWidget {
    ...
    }

  11. #10
    Join Date
    Apr 2007
    Location
    United States
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Lightbulb Re: Setting stylesheet for "almost" all widgets

    Quote Originally Posted by phillip_Qt View Post
    Hi.
    I ve same problem like u. Can u plz tell me how to set default style sheet?
    I tried like setStyleSheet(QString(""));
    But its not working. My code is as follows

    Qt Code:
    1. void NightColor()
    2. {
    3. ptr->LoadStyleSheet("Night");
    4.  
    5. }
    6. void DayColor()
    7. {
    8. setStyleSheet(QString(""));
    9.  
    10. }
    11.  
    12. void Toggle()
    13. {
    14. if(m_iFlag == 0)
    15. NightColor();
    16. else
    17. DayColor();
    18. }
    To copy to clipboard, switch view to plain text mode 

    I ve a push button. if i press it 1st time Nightcolor() ll b called. But if i ll press nxt time default style sheet shd be activated. but its not activating.
    From the look of your code, You are setting a empty style sheet on the global object and not on your "ptr" object. Since the ptr object now has a style, it takes precidence over a global style. To set that object back to "default" use ptr->setStyleSheet("");

  12. #11
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: Setting stylesheet for "almost" all widgets

    Guys... any tip for this?

    Since in my app i have many (example) QPushButtons that follows a common style, but i have many others that have a different style.
    So, an annoying solution was to set the style for ALL buttons using the object names of each one... but if you have many buttons? and what about dialogs created with QMessageBox or worst... a Print Dialog or Print Preview Dialog? you cant know the buttons objects names to style...

    I thinks this is a problem in Qt, and stylesheets should be applied for general style like QPushButton {style} and for each different style using it object name like QPushButton#button {style}... That of course this does not work, since one will override the other...

    Any help here? or is impossible ?

    Thanks in advance...

    Cheers.


    Quote Originally Posted by GuS View Post
    I have same behavior here:

    I am applying a general stylesheets for all widgets. But what i want is that for some kind of same widgets to have another style. So I applied a different stylesheet to those widgets and does not work... it just continue using the general applied stylesheet.

    A Clear Example: I have forms buttons on all over my app so i use a general stylesheet for all those buttons, but i have some buttons that i use for menus/toolbar/etc. that i wish to set a different style, but when i write the stylesheet for those buttons, it still continue using the one applied before. Why?

    Is this possible with Qt4?

    Cheers.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

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.