16,239
社区成员
发帖
与我相关
我的任务
分享
case CC_Slider:
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
QRect groove = subControlRect(CC_Slider, option, SC_SliderGroove, widget);
QRect handle = subControlRect(CC_Slider, option, SC_SliderHandle, widget);
painter->save();
QPixmap grv = cached( tr(":/MyQTInterface/Resources/sliderGroove.png") );//设置进度条图片
QPixmap hndl = cached( tr(":/MyQTInterface/Resources/sliderHandle.png") );//设置滑块图片
QPixmap hndlMove = cached( tr(":/MyQTInterface/Resources/sliderHandleMove.png"));
if ((option->subControls & SC_SliderGroove) && groove.isValid() && handle.isValid()) {
painter->drawPixmap(QRect(groove.x() , groove.y()-2 ,
groove.width(), grv.height()),
grv);
}
//如果被选中
if ((option->subControls & SC_SliderHandle) && (slider->state & State_Sunken))
painter->drawPixmap(handle.topLeft(), hndlMove);
else if((option->subControls & SC_SliderHandle))
painter->drawPixmap(handle.topLeft(), hndl);
painter->restore();
}
break;
QSlider::groove:horizontal {
border: 1px solid #999999;
height: 8px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);
margin: 2px 0;
}
QSlider::handle:horizontal {
background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f);
border: 1px solid #5c5c5c;
width: 18px;
margin: -2px 0; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */
border-radius: 3px;
}
QSlider::groove:vertical {
background: red;
position: absolute; /* absolutely position 4px from the left and right of the widget. setting margins on the widget should work too... */
left: 4px; right: 4px;
}
QSlider::handle:vertical {
height: 10px;
background: green;
margin: 0 -4px; /* expand outside the groove */
}
QSlider::add-page:vertical {
background: white;
}
QSlider::sub-page:vertical {
background: pink;
}