QSlider进度条

<pre name="code" class="css">QSlider::groove:horizontal {
border: none;
height: 3px;

}

QSlider::sub-page:horizontal {
background: qlineargradient(x1: 0.3, y1: 0, x2: 1, y2: 0,
    stop: 0 #00ffec, stop: 1 #f9ff00);
height: 3px;
border-radius: 0px;
}

QSlider::add-page:horizontal {
background: #1b6aac;
border: none;
height: 3px;
border-radius: 0px;
}


QSlider::handle:horizontal 
{
background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:1, fx:0.5, fy:0.5, stop:0.04 rgba(217, 219, 220, 255), stop:0.12 rgba(251, 254, 255, 255),stop:0.25 rgba(251, 254, 255, 0), stop:0.25 rgba(255, 255, 255, 150),stop:0.5 rgba(255, 255, 255, 0));
 	width: 25px;
    margin-top: -12px;
    margin-bottom: -12px;
    border-radius: 4px;
}

QSlider::handle:horizontal:hover {
 background: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, 
    stop:0.3 #2A8BDA, stop:0.778409 rgba(255, 255, 255, 255));
     width: 8px;
    margin-top: -3px;
    margin-bottom: -3px;
    border-radius: 3px;
}


 
 

### 使用Qt样式表自定义QSlider外观 为了使`QSlider`具有独特的视觉效果,可以利用Qt样式表(QSS)。通过这种方式能够调整滑块的颜色、大小以及轨道的样式等属性。 #### 设置基本样式 下面是一个简单的例子来改变水平方向上的`QSlider`: ```css QSlider::groove:horizontal { height: 8px; /* 轨道高度 */ background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4); /* 渐变背景颜色 */ } QSlider::handle:horizontal { background: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 120, 70, 255), stop:1 rgba(255, 90, 40, 255)); /* 圆形按钮填充色 */ border: 2px solid #5c5c5c; width: 18px; margin-2px; margin-bottom: -2px; border-radius: 6px; } ``` 此代码片段设置了滑动条轨道的高度和渐变背景,并修改了手柄部分的颜色及其边框宽度等特性[^1]。 #### 创建类似于进度条的效果 如果希望让`QSlider`看起来更接近于`QProgressBar`,可以通过进一步定制其样式实现这一目标。这里提供了一个更加复杂的案例用于模仿进度条的行为: ```css QSlider{ min-height: 20px; max-height: 20px; } QSlider::sub-page:horizontal { background-color: rgb(100, 100, 255); border: 1px solid rgb(99, 99, 99); } QSlider::add-page:horizontal { background-color: transparent; } QSlider::handle:horizontal { background-color: white; border: 1px solid gray; width: 18px; margin-top: -2px; margin-bottom: -2px; border-radius: 6px; } ``` 上述配置中,“子页面”代表已选中的区域(即左侧),而“附加页”则对应未被选择的部分。“子页面”的背景设为蓝色以模拟已完成的任务比例;相反,“附加页”的透明度设置使得右侧保持空白状态[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值