K--*_*K-- 7 css windows qt stylesheet qpushbutton
我使用的是Qt 5.3.0.当我在QPushButton的选中状态上应用一些背景颜色时,按钮将在选中时用灰色点(我想要的背景颜色)填充.
这是一个很小的测试程序(使用qtcreator,但它也可以通过编码完成):1,创建一个qt应用程序2,拖入QPushButton,将其设置为flat并检查3,在w.show()之前添加这些行
w.setStyleSheet("\
QPushButton { \
color:white; \
} \
QPushButton:checked{\
background-color: rgb(80, 80, 80);\
}\
QPushButton:hover{ \
background-color: grey; \
border-style: outset; \
} \
");
Run Code Online (Sandbox Code Playgroud)
4,运行应用程序并检查按钮
你会看到按钮变成了点缀但是我需要选中的按钮是纯色的rgb(80,80,80).我错过了什么?
Ant*_*ias 16
我可以通过简单地设置样式表border: none;
的QPushButton:checked
属性来删除点.
在你的例子中,它应该是这样的:
w.setStyleSheet("\
QPushButton { \
color:white; \
} \
QPushButton:checked{\
background-color: rgb(80, 80, 80);\
border: none; \
}\
QPushButton:hover{ \
background-color: grey; \
border-style: outset; \
} \
");
Run Code Online (Sandbox Code Playgroud)
在这里,您可以在选中按钮时看到结果: