[SOLVED] Stylesheets: Giving a different color to the checkbox indicator than the text



  • Hello all!

    I've been using css with qt, and it's pretty wonderful. However I came across a problem.

    If you use that:

    @
    QCheckBox {
    color: white;
    }
    @

    For example, you have a black background and so you want to have white text... The problem is that the checkbox indicator becomes white too, instead of staying black, and white on white is invisible (I'm using plastique style).

    Here is an example in how that looks in my app:

    !http://i42.tinypic.com/v5imgg.png(dark theme)!

    (Full picture "here":http://i43.tinypic.com/aca7h1.png)

    If I do:

    @
    QCheckBox::indicator {
    color: black;
    }
    @

    Then the indicator becomes Windows-CE like on windows, it's really bad. And it has no effect on ubuntu.

    So is there a way to do this that I don't know about? Or, where are the indicators stored, so I can do something like:

    @
    QCheckBox::indicator {
    background: url(...);
    }
    QCheckBox::indicator:hover {
    background: url(...);
    }
    QCheckBox::indicator:checked {
    background: url(...);
    }
    QCheckBox::indicator:pressed {
    background: url(...);
    }

    QCheckBox::indicator:hover:checked {
    background: url(...);
    }

    @

    Even if it's a bit tedious.

    Thanks!



  • I don't think the indicator is available by default as an image. QStyle offers the StandardPixmap enum, but I don't spot a checkbox indicator in there. However, if you just use your own image (a screenshot can help you get one), you should be able to follow the Styling QCheckBox example from the Qt Style Sheets Examples page. You can simply use the image property (not the background) property for the check mark.



  • Well thanks it worked!

    For those who have the same problems, the icons are there: http://www.mediafire.com/file/7alp9uzvul6vw11/check-icons.zip



  • Good to know, and thanks for providing your solution!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.