Results 1 to 8 of 8

Thread: Stylesheet for QCheckBox - where does the background color come from?

  1. #1
    Join Date
    Sep 2010
    Posts
    28
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Stylesheet for QCheckBox - where does the background color come from?

    In my QMenu I've added checkable QActions, and I need to style them a bit. As a test I tried:

    Qt Code:
    1. "QMenu::indicator:non-exclusive:unchecked {"
    2. "image: url(:/images/icons/checkmark_grey.png);"
    3. "}"
    4. "QMenu::indicator:non-exclusive:unchecked:selected {"
    5. "image: url(:/images/icons/checkmark_grey.png);"
    6. "}"
    7. "QMenu::indicator:non-exclusive:checked {"
    8. "image: url(:/images/icons/checkmark_grey.png);"
    9. "}"
    10. "QMenu::indicator:non-exclusive:checked:selected {"
    11. "image: url(:/images/icons/checkmark_grey.png);"
    12. "}"
    13. ;
    To copy to clipboard, switch view to plain text mode 

    The png:
    checkmark_grey.png

    When I run my code, the color of the checkmark seems to be set from my png, but the background is grey. I thought it would use my entire png. How do I style the background?

    If I don't apply this stylesheet, the color of the checkable region follows my QMenu stylesheet:

    Qt Code:
    1. "QMenu::item::enabled {"
    2. "color: white;"
    3. "background-color: rgb(66,66,66);"
    4. "selection-color: rgb(66,66,66);"
    5. "selection-background-color: white;"
    6. "}"
    To copy to clipboard, switch view to plain text mode 

    What I'm basically trying to do is make the color and background of the checkbox follow item colors.

  2. #2
    Join Date
    Sep 2010
    Posts
    28
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Stylesheet for QCheckBox - where does the background color come from?

    After styling my QMenu, but not QMenu::indicator, my menus look like this:
    thefirst.png
    thesecond.png
    Kinda nice, but with I need to swap colors, and ideally make the black checkmark grey instead.

    After adding my own images to QMenu::indicator:
    theturd.png
    the_fourth.png

    When all I wanted to do was change the colors of the checkmarks. Anyone got any ideas about 1) what's wrong, and 2) what I should do?

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Stylesheet for QCheckBox - where does the background color come from?

    Post some code how you've styled the menu so we can tell you what's wrong and other can benefit from your example.

  4. #4
    Join Date
    Sep 2010
    Posts
    28
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Stylesheet for QCheckBox - where does the background color come from?

    There's not much more code to post than what I've added above.

    The entire stylesheet:

    Qt Code:
    1. QString MenuStyle =
    2. "QMenu::item::enabled {"
    3. "color: white;"
    4. "background-color: rgb(66,66,66);"
    5. "selection-color: rgb(66,66,66);"
    6. "selection-background-color: white;"
    7. "}"
    8. "QMenu::item::disabled {"
    9. "background-color: rgb(66,66,66);"
    10. "}"
    11. "QMenu::separator {"
    12. "height: 1px;"
    13. "background: lightgrey;"
    14. "margin-left: 3px;"
    15. "margin-right: 5px;"
    16. "}"
    17. "QMenu::indicator:non-exclusive:unchecked {"
    18. "image: url(:/images/icons/checkmark_white.png);"
    19. "}"
    20. "QMenu::indicator:non-exclusive:checked {"
    21. "image: url(:/images/icons/checkmark_grey.png);"
    22. "}"
    23. "QMenu::indicator:non-exclusive:checked:selected {"
    24. "image: url(:/images/icons/checkmark_white.png);"
    25. "}";
    To copy to clipboard, switch view to plain text mode 

    Anything else I can post that would be of help?

  5. #5
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: Stylesheet for QCheckBox - where does the background color come from?

    This works for me so I guess you are doing the right thing.

    Qt Code:
    1. /*----------------------------------------------------------------------------*/
    2. /*----------------------------------------------------------------------------*/
    3. background-color: rgb(58, 69, 91);
    4. color: rgb(220, 221, 226);
    5. border: 0px solid red;
    6. padding: 5px;
    7. }
    8.  
    9. QMenu::item{
    10. background-color: transparent;
    11. border: 1px solid transparent;
    12. padding: 2px 25px 2px 20px;
    13. }
    14.  
    15. QMenu::item:selected{
    16. background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(146, 156, 182), stop:1 rgb(88, 99, 121));
    17. border: 1px solid transparent;
    18. color: rgb(220, 221, 226);
    19. }
    20.  
    21. QMenu::separator{
    22. height: 1px;
    23. color: rgb(220, 221, 226);
    24. margin: 5px 25px 5px 20px;
    25. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Sep 2010
    Posts
    28
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Stylesheet for QCheckBox - where does the background color come from?

    Until I add the QMenu::indicator stuff it works for me too, but then "everything" changes.

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Stylesheet for QCheckBox - where does the background color come from?

    Possibly because the white portion of your checkmark image is not transparent so it is overlaying the background when it is painted. Try the attached image: checkmark_grey.png

  8. #8
    Join Date
    Sep 2010
    Posts
    28
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Stylesheet for QCheckBox - where does the background color come from?

    I will (when I get to work), but that can't be all that happens? If you look at my screenshots, all the colors change when I add the checkmark image.

Similar Threads

  1. Replies: 1
    Last Post: 27th May 2011, 20:27
  2. Replies: 4
    Last Post: 2nd December 2010, 14:57
  3. QCheckBox change color
    By vajindarladdad in forum Newbie
    Replies: 4
    Last Post: 6th October 2009, 08:33
  4. How to change defualt color of QCheckbox box?
    By darshan.hardas in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2008, 13:24
  5. qCheckbox back ground color
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2006, 18:44

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.