Results 1 to 6 of 6

Thread: Style Sheet Syntax background

  1. #1
    Join Date
    Jul 2009
    Location
    Switzerland
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Style Sheet Syntax background

    I want to have the background only from a QWidget black. The background from the QPushbuttons, QSliders etc. shoud be normal.
    I use the Style-Syntax:

    QWidget {
    background-color:rgb(20, 20, 20);
    }

    I read in the Qt Assistant (Stylesheet-Syntax) that i must make bevore the QWidget a point:

    .QWidget {
    background-color:rgb(20, 20, 20);
    }

    I have now the problam that this didn't work.

    Thanks for help.

  2. #2
    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: Style Sheet Syntax background

    well it works, but only for QWidgets! No subclass, even not your own if they only inherit QWidget.

    maybe you provide a small executable example showing your problem.

  3. #3
    Join Date
    Jul 2009
    Location
    Switzerland
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Style Sheet Syntax background

    I had this code and it didn't work, the background from the QWidget wouldn't be darker:

    Qt Code:
    1. QColor bgColor = palette().color(QPalette::Window).darker(110);
    2. QString styleSheet = ".QWidget { background-color:rgb(%1, %2 ,%3);}";
    3. styleSheet = styleSheet.arg(bgColor.red()).arg(bgColor.green()).arg(bgColor.blue());
    4. setStyleSheet(styleSheet);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: Style Sheet Syntax background

    Well your are setting the style sheet on what kind of object? I seems that is is a subclass, which, as told, wont work. But you can use ".NAMEOFYOURCLASS" and then it should work.
    Last edited by Lykurg; 27th April 2010 at 15:24. Reason: updated contents

  5. #5
    Join Date
    Jul 2009
    Location
    Switzerland
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Style Sheet Syntax background

    Yes, it's a own subclass from QWidget. I use:
    Qt Code:
    1. QString styleSheet = ".myOwnClass {background-color:rgb(%1, %2, %3)}";
    To copy to clipboard, switch view to plain text mode 
    but it didnt' work. I think it's a problem of the syntax, because
    Qt Code:
    1. QString styleSheet = "QWidget {background-color:rgb(%1, %2, %3)}";
    To copy to clipboard, switch view to plain text mode 
    works and
    Qt Code:
    1. QString styleSheet = ".QWidget {background-color:rgb(%1, %2, %3)}";
    To copy to clipboard, switch view to plain text mode 
    didn't work.

  6. #6
    Join Date
    Jul 2009
    Location
    Switzerland
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Style Sheet Syntax background

    I solved the problem:

    Qt Code:
    1. QString styleSheet = "QWidget#MyOwnClass {background-color:rgb(%1, %2, %3)}";
    To copy to clipboard, switch view to plain text mode 

    Now it works.
    But I don't now why the other syntax don't work.

    Thanks for your efforts

Similar Threads

  1. Problems with Gradient style used through Style sheet on ARM platform
    By puneet.narsapur in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 25th January 2010, 12:48
  2. Inherited Style Sheet
    By johnmauer in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2010, 21:07
  3. Slider Style sheet
    By sijithjames in forum Qt Programming
    Replies: 2
    Last Post: 30th December 2009, 12:43
  4. Qt 4.3 Style sheet, new features
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2007, 15:22
  5. How to use style sheet
    By safknw in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2006, 13:05

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.