QSlider在不同平台上的显示方式不同。如何获得a的width
and height
,是否使用CSS设置样式?我只知道检索整个QWidget的方法,但不知道?handle
QSlider
size
handle
问问题
1105 次
2 回答
1
有一种可怕的方法,它可能不必正常工作,但它仍然有效:
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;
}
于 2020-10-05T19:03:30.713 回答
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;
}
于 2017-01-11T09:14:00.077 回答