转自:

https://blog.csdn.net/tax10240809163com/article/details/50899023

//首先是设置主体
QSlider{
border-color: #bcbcbc;
}
QSlider::groove:horizontal {
border: 1px solid #999999;
height: 1px;
margin: 0px 0;
left: 5px; right: 5px;
}
//设置中间的那个滑动的键
QSlider::handle:horizontal {
border: 0px ;
border-image: url(:/NiceTalk/Images/Setting/volume_nor.png);
width: 15px;
margin: -7px -7px -7px -7px;
}
//还没有滑上去的地方
QSlider::add-page:horizontal{
background: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 #bcbcbc, stop:0.25 #bcbcbc, stop:0.5 #bcbcbc, stop:1 #bcbcbc);

}
//已经划过的从地方
QSlider::sub-page:horizontal{
background: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 #439cf3, stop:0.25 #439cf3, stop:0.5 #439cf3, stop:1 #439cf3);
}

下面看下Pyqt下面怎么使用:

slider = QSlider(Qt.Horizontal)
slider.setFixedSize(155, 15)
slider.setStyleSheet("""
    QSlider {border-color: #bcbcbc;}
    QSlider::groove:horizontal {border: 1px solid #999999;height: 1px; margin: 0px 0px;left: 5px; right: 5px;}
    QSlider::handle:horizontal {border: 0px ;border-image: url(application/resources/icons/handle.png);width: 13px;margin: -7px -7px -7px -7px;}
    QSlider::add-page:horizontal {background: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 #bcbcbc, stop:0.25 #bcbcbc, stop:0.5 #bcbcbc, stop:1 #bcbcbc);}
    QSlider::sub-page:horizontal {background:rgb(156,195,206);}
  """)

posted on 2018-07-18 16:15  邶风  阅读(2643)  评论(0编辑  收藏  举报