两种QSlider进度条的QSS样式

1. 横的进度条:



musicSlider->setStyleSheet("  \
     QSlider::add-page:Horizontal\
     {     \
        background-color: rgb(87, 97, 106);\
        height:4px;\
     }\
     QSlider::sub-page:Horizontal \
    {\
        background-color:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(231,80,229, 255), stop:1 rgba(7,208,255, 255));\
        height:4px;\
     }\
    QSlider::groove:Horizontal \
    {\
        background:transparent;\
        height:6px;\
    }\
    QSlider::handle:Horizontal \
    {\
        height: 30px;\
        width:8px;\
        border-image: url(:/images/ic_music_thumb.png);\
        margin: -8 0px; \
    }\
    ");

由于采用样式,原始的拖动滑块消失,采用ic_music_thumb.png来当拖动滑块。

   <- -    ic_music_thumb.png




2. 竖的进度条,有底色。圆形滑块。


volumeSlider->setStyleSheet("  \
    QSlider\
    {\
        background-color: rgb(25, 38, 58);\
        min-width:5px;\
        max-width:5px;\
        border:15px solid rgb(25, 38, 58);\
    }\
     QSlider::add-page:vertical\
     {     \
        background-color: rgb(37, 168, 198);\
        width:4px;\
     }\
     QSlider::sub-page:vertical \
    {\
        background-color: rgb(87, 97, 106);\
        width:4px;\
     }\
    QSlider::groove:vertical \
    {\
        background:transparent;\
        width:6px;\
    }\
    QSlider::handle:vertical \
    {\
         height: 13px;\
        width:13px;\
        border-image: url(:/images/ic_volume_thumb.png);\
         margin: -0 -4px; \
     }\
    ");

 <--    ic_volume_thumb.png

当然可以,以下是三个QSlider样式代码,你可以根据自己的需要进行修改和使用。 1. 基本样式 ```qss QSlider { background-color: transparent; height: 20px; } QSlider::groove:horizontal { border: 1px solid #bbb; background: #ccc; height: 3px; border-radius: 2px; } QSlider::handle:horizontal { background: #fff; border: 1px solid #bbb; width: 10px; height: 10px; margin: -4px 0; border-radius: 5px; } ``` 2. 带刻度的样式 ```qss QSlider { background-color: transparent; height: 20px; } QSlider::groove:horizontal { border: 1px solid #bbb; background: #ccc; height: 3px; border-radius: 2px; } QSlider::handle:horizontal { background: #fff; border: 1px solid #bbb; width: 10px; height: 10px; margin: -4px 0; border-radius: 5px; } QSlider::sub-page:horizontal { background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #bbb, stop: 1 white); border: 1px solid #777; height: 3px; border-radius: 2px; } QSlider::add-page:horizontal { background: #fff; border: 1px solid #777; height: 3px; border-radius: 2px; } QSlider::handle:horizontal:hover { background: #eee; border: 1px solid #888; } QSlider::sub-page:horizontal:disabled { background: #bbb; border-color: #999; } QSlider::add-page:horizontal:disabled { background: #eee; border-color: #999; } QSlider::handle:horizontal:disabled { background: #eee; border: 1px solid #aaa; border-radius: 5px; } QSlider::groove:horizontal:disabled { background: #eee; border: 1px solid #aaa; height: 3px; border-radius: 2px; } QSlider::handle:horizontal:pressed { background: #ccc; border: 1px solid #444; } QSlider::tick-line:horizontal { background: #bbb; width: 1px; height: 12px; } ``` 3. 垂直滑块样式 ```qss QSlider { background-color: transparent; width: 20px; } QSlider::groove:vertical { border: 1px solid #bbb; background: #ccc; width: 3px; border-radius: 2px; } QSlider::handle:vertical { background: #fff; border: 1px solid #bbb; width: 10px; height: 10px; margin: 0 -4px; border-radius: 5px; } QSlider::sub-page:vertical { background: qlineargradient(x1: 0, y1: 1, x2: 0, y2: 0, stop: 0 #bbb, stop: 1 white); border: 1px solid #777; width: 3px; border-radius: 2px; } QSlider::add-page:vertical { background: #fff; border: 1px solid #777; width: 3px; border-radius: 2px; } QSlider::handle:vertical:hover { background: #eee; border: 1px solid #888; } QSlider::sub-page:vertical:disabled { background: #bbb; border-color: #999; } QSlider::add-page:vertical:disabled { background: #eee; border-color: #999; } QSlider::handle:vertical:disabled { background: #eee; border: 1px solid #aaa; border-radius: 5px; } QSlider::groove:vertical:disabled { background: #eee; border: 1px solid #aaa; width: 3px; border-radius: 2px; } QSlider::handle:vertical:pressed { background: #ccc; border: 1px solid #444; } QSlider::tick-line:vertical { background: #bbb; width: 12px; height: 1px; } ```
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值