【转载】【原】QPushButton 的样式表代码总结

 

最近刚开始学做qt界面,网上很多例子。自己摸索后,才会有更深刻的总结。

 

方法1:对QPushButton的美化,很多人都用setFlat(),将QPushButton扁平后,再美化。

但是它有一个缺点,就是无法再通过SetStyleSheet()对它上色。除非用QPalette:Button系统的颜色。这个就不太方便了。

 

方法2:或者网上说的QLinkButton,但是它无法将字体充满在button内部。

 

但是实际上不需要上述方法,照样使用qt原风格的Button,

【原】QPushButton 的样式表代码总结 - 柳北风儿 - 柳北风儿~~~~~~~欲宇仙炅

 

只需要在qss中修改它的风格就好了,而且不影响背景着色。

 

  1. QPushButton#fileBtn,#helpBtn,#settingBtn{  
  2.     border: 1px solid #C0C0C0;  
  3.     background-color:#C0C0C0;  
  4.     border-style: solid;  
  5.     border-radius:0px;  
  6.     width: 40px;  //和你的控件大小一致
  7.     height:20px;  //和你的控件大小一致
  8.     padding:0 0px;  
  9.     margin:0 0px;  
  10. }  
  11. QPushButton#expBtn{  
  12.     border: 1px solid #C0C0C0;  
  13.     background-color:#FFFFFF;  
  14.     border-style: solid;  
  15.     border-radius:0px;  
  16.     width: 100px;  
  17.     height:20px;  
  18.     padding:0 0px;  
  19. }  
  20. QPushButton#fileBtn:hover,#helpBtn:hover,#settingBtn:hover,#expBtn:hover{     
  21.     border: 1px solid #E3C46F;  
  22.     background-color:#FEF4BF;  
  23.     border-style: solid;  
  24.     border-radius:2px;  
  25.     width: 40px;  
  26.     height:20px;  
  27.     padding:0 0px;  
  28. }  
  29. QPushButton#fileBtn:pressed,#helpBtn:pressed,#settingBtn:pressed,#expBtn:pressed{  
  30.     background-color:#EAF0FF;  
  31.     border: 1px solid #AAB4C4;  
  32.     width: 40px;  
  33.     height:20px;  
  34.     padding:0 0px;  
  35.     border-radius:1px;  
  36. }  

 

 运行后效果如下图:

【原】QPushButton 的样式表代码总结 - 柳北风儿 - 柳北风儿~~~~~~~欲宇仙炅

 

//固定按钮的大小

QPushButton { 
    min-height: 150px; 
    min-width: 150px;  
    max-width: 150px; 
    max-height: 150px; 
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值