Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to style QPushButton's checked state to remove grey dots?

I am using Qt 5.3.0. When I apply some background-color on the QPushButton's checked state, the button will be filled with grey dots (over the background color I wanted) when it is checked.

Here is a tiny test program (with qtcreator but it can also be done with coding): 1, create an qt application 2, drag in a QPushButton, set it to flat and checkable 3, add these lines before w.show()

w.setStyleSheet("\
                QPushButton {   \
                    color:white;    \
                }   \
                QPushButton:checked{\
                    background-color: rgb(80, 80, 80);\
                }\
                QPushButton:hover{  \
                    background-color: grey; \
                    border-style: outset;  \
                }  \
                ");

4, run the app and check the button

You'll see the button turns to dotted but I need the checked button to be in solid color as rgb(80, 80, 80). Did I miss something?

like image 248
K-- Avatar asked Jul 13 '14 01:07

K--


1 Answers

I'm able to remove the dots by simply set border: none; on the QPushButton:checked property of stylesheet.

On your example, it should be like this:

w.setStyleSheet("\
                QPushButton {   \
                    color:white;    \
                }   \
                QPushButton:checked{\
                    background-color: rgb(80, 80, 80);\
                    border: none; \
                }\
                QPushButton:hover{  \
                    background-color: grey; \
                    border-style: outset;  \
                }  \
                ");

And here you can see the result when the button is checked:

enter image description here

like image 76
Antonio Dias Avatar answered Nov 04 '22 21:11

Antonio Dias