QT学习1 QSlider 更改样式

Seriously. I don’t know how I ever created a Qt user interface without using stylesheets. This was, by far, the best idea Trolltech ever had.

For today’s show-and-tell, I give you a nifty-looking QSlider with some nice gradient style applied to it:

The handle has a nice hover effect, the bar has a moving gradient as you slide the slider, and it looks good when disabled. Notice also the rounded corners. No image files were harmed in the making of this widget.

Here’s the stylesheet code (I used Qt’s example as a starting point).

[css]  view plain  copy
  1. QSlider::groove:horizontal {  
  2. border1px solid #bbb;  
  3. backgroundwhite;  
  4. height10px;  
  5. border-radius: 4px;  
  6. }  
  7.   
  8. QSlider::sub-page:horizontal {  
  9. background: qlineargradient(x1: 0, y1: 0,    x2: 0, y2: 1,  
  10.     stop: 0 #66e, stop: 1 #bbf);  
  11. background: qlineargradient(x1: 0, y1: 0.2, x2: 1, y2: 1,  
  12.     stop: 0 #bbf, stop: 1 #55f);  
  13. border1px solid #777;  
  14. height10px;  
  15. border-radius: 4px;  
  16. }  
  17.   
  18. QSlider::add-page:horizontal {  
  19. background#fff;  
  20. border1px solid #777;  
  21. height10px;  
  22. border-radius: 4px;  
  23. }  
  24.   
  25. QSlider::handle:horizontal {  
  26. background: qlineargradient(x1:0, y1:0, x2:1, y2:1,  
  27.     stop:0 #eee, stop:1 #ccc);  
  28. border1px solid #777;  
  29. width13px;  
  30. margin-top-2px;  
  31. margin-bottom-2px;  
  32. border-radius: 4px;  
  33. }  
  34.   
  35. QSlider::handle:horizontal:hover {  
  36. background: qlineargradient(x1:0, y1:0, x2:1, y2:1,  
  37.     stop:0 #fff, stop:1 #ddd);  
  38. border1px solid #444;  
  39. border-radius: 4px;  
  40. }  
  41.   
  42. QSlider::sub-page:horizontal:disabled {  
  43. background#bbb;  
  44. border-color#999;  
  45. }  
  46.   
  47. QSlider::add-page:horizontal:disabled {  
  48. background#eee;  
  49. border-color#999;  
  50. }  
  51.   
  52. QSlider::handle:horizontal:disabled {  
  53. background#eee;  
  54. border1px solid #aaa;  
  55. border-radius: 4px;  
  56. }  


附:有用的border-radius相关项

 "border-top-left-radius: 12px;\n"
  "border-bottom-left-radius: 12px;\n"
  "border-top-right-radius: 12px;\n"
   "border-bottom-right-radius: 12px;\n"


Enjoy!

//add :groove为槽的颜色,handle为按钮的颜色,add-page 及sub-page分别问按钮前后的颜色,如果groove与add-page、sub-page同在,那么groove的颜色会被覆盖掉。


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值