Qt之样式表QPushButton详细制作方法
2022-10-18 01:52 作者:SilverFox_Ankha | 我要投稿

前言
制作不易 多多支持
点赞关注 万分感谢
个人经验分享,望各位少走弯路
日后如果有新发现,我会实时更新这个专栏
PyQt5学习爱好群主群:732513891(已满)
PyQt5学习爱好群二群:937759168(已满)
PyQt5学习爱好群三群:757679170

*注意:作者本人Macos系统,和windows可能有些许不同
QPushButton

在Mac中,如果按钮输入中文文字,必须保持高度不超过32,否则会丢失原始样式。如果设定maximunsize的高度锁定为32,则不会发生样式变化。



QPushButton{
color: rgb(255, 255, 255);
background-color: rgba(165, 205, 255,125);
border:1px outset rgb(255, 255, 255);
border-radius:8px;
text-align: center center;
}
文字为白色、背景颜色为天蓝色透明度为125、边框为1px的凹陷白色边框、圆角为8px,文字排版为横纵居中。
/*鼠标放在按钮上方*/
QPushButton:hover {
background-color: rgba(165, 205, 255,80%);
border:2px outset rgba(36, 36, 36,0);
}
继承QPushButton开始的样式并且添加,背景色为天蓝色,提升透明度到80%,增加边框为2px的凹陷透明边框。
/*鼠标点击按钮*/
QPushButton:pressed {
background-color: rgba(165, 205, 255,90%);
border:4px outset rgba(36, 36, 36,0);
}
继承QPushButton开始的样式并且添加,背景颜色透明度提升至90%,增加4px透明边框。


QPushButton{
color: rgb(255, 255, 255);
background-color: rgba(165, 205, 255,125);
border:1px outset rgb(255, 255, 255);
border-radius:8px;
text-align: bottom;
image: url(:/svg/img/svg/男孩3.png);
image-position: top; /* 背景图片的位置 */
padding-bottom: 18px; /* 背景图标的padding参数 */
background-repeat: no-repeat; /*repeat-y,repeat-x*/
}
带有图片,并且图片在上,文字在下的按钮。


/*按钮设置为flat状态时*/
QPushButton:flat {
border:2px solid red;
}
/*按钮设置为default状态时*/
QPushButton:default {
border:2px solid blue;
}
可以按照按钮的不同形态进行样式设定。


QPushButton{
margin-right:3px;
margin-bottom:0px;
color: rgb(255, 255, 255);
background-color: rgba(165, 205, 255,125);
border:1px outset rgb(255, 255, 255);
border-radius:8px;
font-family: "Microsoft YaHei";
font-size: 14px;
font-style: italic;
font-weight: bold;
font: bold italic 18px "Microsoft YaHei";
}
带有文字字体、文字大小、文字风格、文字加粗、等风格的按钮。

那么Pushbutton就大概涵盖这些,如果有遗漏请大家私信我,后续如果有发现新的玩法,会及时更新文章,希望大家多多关注点赞支持我。后续我会把其他控件的相关用法也写出来。如果有深入学习和交流可以加群,群里有很多小伙伴可以一起讨论问题。
PyQt5学习爱好群主群:732513891(已满)
PyQt5学习爱好群二群:937759168(已满)
PyQt5学习爱好群三群:757679170
谢谢观看
