目录
1、QPushButton样式表设置背景色 background-color无效的原因
1、QPushButton样式表设置背景色 background-color无效的原因

想使背景色生效,必须要设置一下某个border属性,border-color、border-width等等任何一个跟border相关的属性都行。因为pushbutton的原生边界把背景色给覆盖住了。
2、样式表属性总结
1. 设置高、宽度。单位:像素(px)
width:12px; //设置宽度 单位像素
height:40px //设置高度
min-width:65px; //最小宽度 有些时候设置width无效可以尝试设置min-width
min-height:12px; //最小高度
max-width:12px;
max-height:12px;
2. 设置背景颜色 四种颜色表示方式
background-color:rgb(255,255,255);
background-color:rgbs(255,255,255,30); //最后一个参数是透明度 0~255
background-color:yellow //常用颜色名
background-color:#FF0000
3. 文本颜色
colo:rgb(255,255,255); //前景色 文本颜色
color: #F5F5F5; //前景(文本)颜色
4. 边框
border:3px solid red //边框---可以分开设置 solid 实线 dotted 点状边框 none无边框 dashed 虚线
border---四条边相同样式
border-style
border-top-style
border-right-style
border-bottom-style
border-left-style
border-width 上 右 下 左 ----- 边框宽度 //3px 边框像素---宽度-单位:像素(px)
border-top-width
border-right-width
border-bottom-width
border-left-width
border: 1px solid #FDBC03; /* 边框:宽度 颜色*/
border-radius: 4px; /*边框圆角半径 */
border-top-left-radius: ; /* 角弧度:左上角*/
border-top-right-radius: ; /* 角弧度:右上角*/
border-bottom-left-radius: ; /* 角弧度:左下角*/
border-bottom-right-radius: ; /* 角弧度:右下角*/
border-color: //边框颜色 上 右 下 左
border-top-color
border-right-color
border-bottom-color
border-left-color
5. 伪状态列表
:checked //button部件被选中
:unchecked //button部件未被选中
:disabled //部件被禁用
:enabled //部件被启用
:focus //部件获得焦点
:hover //鼠标位于部件上
:indeterminate //checkbox或radiobutton被部分选中
:off //部件可以切换,且处于off状态
:on //部件可以切换,且处于on状态
:pressed //部件被鼠标按下
6. 子部件
::down-arrow //combo box或spin box的下拉箭头
::down-button //spin box的向下按钮
::drop-down //combo box的下拉箭头
::indicator //checkbox、radio button或可选择group box的指示器
::item //menu、menu bar或status bar的子项目
::menu-indicator //push button的菜单指示器
::title //group box的标题
::up-arrow //spin box的向上箭头
::up-button //spin box的向上按钮
文章探讨了为什么在QPushButton中设置background-color无效,原因是原始边框覆盖了背景色,解决方法是设置任何border属性。同时,总结了样式表属性,包括尺寸、颜色、边框、伪状态和子部件的设置。另外,提到了QListWidget使用setItemWidget时可能出现的QListItemWidget隐藏的Bug。

1258

被折叠的 条评论
为什么被折叠?



