QML Slider:手柄和鼠标光标
QML Slider : handle and mouse cursor
我在一个项目中创建了一个滑块并按照以下代码对其进行了自定义:
Item {
id: item1
x: 0
y: 0
width: 200
height: parent.height
Rectangle {
id: background
anchors.fill: parent;
color:Qt.rgba(0.9,0.9,0.9,1);
}
Slider {
anchors.centerIn: parent
orientation: Qt.Vertical
height: parent.height
style: SliderStyle {
groove: Rectangle {
implicitWidth: 200
implicitHeight: 8
color: "gray"
radius: 8
}
handle: Rectangle {
anchors.centerIn: parent
color: control.pressed ? "white" : "lightgray"
border.color: "gray"
border.width: 2
width: 20
height: 20
radius: 6
}
}
}
}
当我将手柄的尺寸更改为宽度大于高度时出现问题,因此我更改了手柄:
width: 20
height: 80 //the height is changed instead of width but I think
//it's because it is a vertical slider
然后,当我移动手柄时,它并没有停留在鼠标光标下,而是两者之间有一个偏移量。
如何解决?
当方向为垂直时,滑块为 internally rotated 90 degrees,因此您需要设置 width
而不是 height
。换句话说,始终假定滑块是水平的来设置手柄的样式,其余的将正常工作...
... 除了您刚刚 运行 遇到的鼠标偏移错误。您的用例似乎不是 auto-tested. Please submit a bug report at bugreports.qt.io.
我在一个项目中创建了一个滑块并按照以下代码对其进行了自定义:
Item {
id: item1
x: 0
y: 0
width: 200
height: parent.height
Rectangle {
id: background
anchors.fill: parent;
color:Qt.rgba(0.9,0.9,0.9,1);
}
Slider {
anchors.centerIn: parent
orientation: Qt.Vertical
height: parent.height
style: SliderStyle {
groove: Rectangle {
implicitWidth: 200
implicitHeight: 8
color: "gray"
radius: 8
}
handle: Rectangle {
anchors.centerIn: parent
color: control.pressed ? "white" : "lightgray"
border.color: "gray"
border.width: 2
width: 20
height: 20
radius: 6
}
}
}
}
当我将手柄的尺寸更改为宽度大于高度时出现问题,因此我更改了手柄:
width: 20
height: 80 //the height is changed instead of width but I think
//it's because it is a vertical slider
然后,当我移动手柄时,它并没有停留在鼠标光标下,而是两者之间有一个偏移量。
如何解决?
当方向为垂直时,滑块为 internally rotated 90 degrees,因此您需要设置 width
而不是 height
。换句话说,始终假定滑块是水平的来设置手柄的样式,其余的将正常工作...
... 除了您刚刚 运行 遇到的鼠标偏移错误。您的用例似乎不是 auto-tested. Please submit a bug report at bugreports.qt.io.