微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

css – 如何设置QPushButton的选中状态以去除灰点?

我使用的是Qt 5.3.0.当我在QPushButton的选中状态上应用一些背景颜色时,按钮将在选中时用灰色点(我想要的背景颜色)填充.

这是一个很小的测试程序(使用qtcreator,但它也可以通过编码完成):
1,创建一个qt应用程序
2,拖入QPushButton,将其设置为平坦且可检查
3,在w.show()之前添加这些行

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

4,运行应用程序并检查按钮

你会看到按钮变成了点缀但是我需要选中的按钮是纯色的rgb(80,80).
我错过了什么?

解决方法

我只需设置border:none即可删除这些点;在样式表的QPushButton:checked属性上.

在你的例子中,它应该是这样的:

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

在这里,您可以在选中按钮时看到结果:

原文地址:https://www.jb51.cc/css/214874.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。