Results 1 to 7 of 7

Thread: System stylesheet

  1. #1
    Join Date
    Jul 2007
    Posts
    121
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    38
    Thanked 3 Times in 3 Posts

    Default System stylesheet

    I am very new to the subject of stylesheets. Mainly I was just changing some background colors on the frames and that's all. I hit the problem that discussed here several times, namely - how to specify default (or system) color?

    I have a custom stylesheet for a tab widget and want to keep all buttons "grey", as they were before applying the stylesheet on a tab. Reading previous discussions did not help me much, so I am asking this question again - is therea command for a style sheet that reverts the background color to be a system color, something like: background-color: system?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: System stylesheet

    what do u mean system color ? By default the widgets appear as normal window color only, isnt it ?

  3. #3
    Join Date
    Sep 2008
    Posts
    25
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 5 Times in 5 Posts

    Default Re: System stylesheet

    Hi QPlace!

    So your problem is , that you've changed the background color of a frame, and it changed the color of all its children's background?
    If all you want to do, is to revert the changes on the children try this:
    "QAbstractButton { background-color: palette(button); }".
    You can use any other color from the widgets palette.

  4. #4
    Join Date
    Jul 2007
    Posts
    121
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    38
    Thanked 3 Times in 3 Posts

    Default Re: System stylesheet

    Hi guys, thanks for the replies.

    I have attached a screenshot to illustrate the problem. Screenshots were taken in the Qt designer.

    Fig. 1 shows part of the dialog where I changed the root QWidget's stylesheet to the one shown. As you can see the buttons are now using this yellowish stylesheet (although Qt designer's visible stylesheet property for these buttons is an empty strings).

    Fig. 2 shows part of the same dialog where I applied gsmico's advise to one of the buttons. Indeed the button is now "grey".

    Fig. 3 shows part of different dialog where the default buttons are visible. Please notice the difference in looks between Fig.3 and Fig.2 buttons. Specifically, Fig.3 has vertical gradient and Fig.2 does not.

    I am sure that there is a possibility to construct a stylesheet for a button that will mimic the appearance of the default button. What I want to have is, when specifying stylesheet for a central Widget, somehow tell him - "leave the buttons (or other widgets to that matter) alone, don't change it, so they retain the system look."

    Any help/advise is greatly appreciated.


  5. #5
    Join Date
    Sep 2008
    Posts
    25
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 5 Times in 5 Posts

    Default Re: System stylesheet

    Thanks for the screen shots. I finally understood what's your problem.
    One of the solutions would be to explicitly specify the widget. For example if you want to change the stylesheet of a widget called "MyWidget", and if you don't want it to affect the appearance of it's children, then do this:
    "#MyWidget
    {
    background-color:<some-color>;
    }"
    Another solution would be to specify a single widget type, in your stylesheet, and deny it to affect the widget's children.
    ".QWidget
    {
    background-color:<some-color>;
    }".
    I suggest to read the style sheet syntax documentation.
    The Style Sheet Syntax

  6. The following user says thank you to gsmiko for this useful post:

    QPlace (23rd June 2009)

  7. #6
    Join Date
    Jul 2008
    Posts
    69
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    9
    Thanked 4 Times in 4 Posts

    Default Re: System stylesheet

    Thanks guys

    example of stylesheet inside the mainwindow.cpp
    Qt Code:
    1. void MainWindow::testStyleSheet1(){
    2. this->setStyleSheet(" QPushButton:hover { color: rgb(53, 201, 255) }QPushButton , QLineEdit, QComboBox, QLabel, QMenuBar { color: blue }");
    3. }
    To copy to clipboard, switch view to plain text mode 

    I also use to revert to the default:
    Qt Code:
    1. void MainWindow::testStyleSheetdefault(){
    2. this->setStyleSheet(" default");
    3. }
    To copy to clipboard, switch view to plain text mode 

    hope this help

  8. #7
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    8
    Thanked 7 Times in 7 Posts

    Default Re: System stylesheet

    Buttons and most of the GUI controls are derived from QWidget. If you apply the stylesheet to parent the child also takes the property. To avoid this child inheriting the stylesheet property
    use "." beside the parent class name.

    Qt Code:
    1. For ex:
    2. Instead,
    3.  
    4. background-color: #ffffff;
    5. }
    6.  
    7. use like this,
    8.  
    9. background-color: #ffffff;
    10. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 7
    Last Post: 12th January 2011, 22:01
  2. Using QT for Digital TV menu system?
    By mittalpa in forum Newbie
    Replies: 4
    Last Post: 2nd July 2008, 19:23
  3. System environment variable
    By fahlen in forum Qt Programming
    Replies: 4
    Last Post: 27th November 2007, 19:02
  4. coordinating system
    By eleanor in forum Qt Programming
    Replies: 3
    Last Post: 7th November 2007, 20:57
  5. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15

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
  •  
Qt is a trademark of The Qt Company.