QSliders在不同平台上的显示方式不同。我如何获得width
height
的{{1}}和handle
,是否使用CSS进行样式设置?
我只知道检索整个QWidget的QSlider
的方法,而不是size
的<{1}}?
答案 0 :(得分:0)
QSlider::groove:horizontal
{
border: 1px solid #bbb;
background: white;
height: 10px;
border-radius: 4px;
}
QSlider::sub-page:horizontal
{
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #66e, stop: 1 #bbf);
background: qlineargradient(x1: 0, y1: 0.2, x2: 1, y2: 1,
stop: 0 #bbf, stop: 1 #55f);
border: 1px solid #777;
height: 10px;
border-radius: 4px;
}
QSlider::add-page:horizontal
{
background: #fff;
border: 1px solid #777;
height: 10px;
border-radius: 4px;
}
QSlider::handle:horizontal
{
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 #eee, stop:1 #ccc);
border: 1px solid #777;
width: 13px;
margin-top: -2px;
margin-bottom: -2px;
border-radius: 4px;
}
QSlider::handle:horizontal:hover
{
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 #fff, stop:1 #ddd);
border: 1px solid #444;
border-radius: 4px;
}
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: 4px;
}
答案 1 :(得分:0)
有一种糟糕的方法,虽然不一定能正常工作,但仍然可行:
QSize sliderHandleSize( const QSlider& slider )
{
const QSize _minSize = slider.minimumSizeHint();
switch( slider.orientation() )
{
case Qt::Orientation::Horizontal:
return QSize( _minSize.width() - 1, _minSize.height() );
case Qt::Orientation::Vertical:
return QSize( _minSize.width(), _minSize.height() - 1 );
default:
Q_ASSERT_X( false, "sliderHandleSize", "Today is a bad day" );
}
return _minSize;
}