QPushButton 的样式表代码总结

来源:互联网 发布:php过滤所有html标签 编辑:程序博客网 时间:2024/06/10 03:26

最近刚开始学做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; }

原文链接:http://blog.163.com/qimo601@126/blog/static/15822093201432494134937/

原创粉丝点击