我在玩RangeSlider,我正在尝试创建一个支点值,其中第一个不能超过这个值,第二个不能低于这个值。
RangeSliderFixed.qml
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1
Item {
id: root
property int minValue: 0
property int maxValue: 100
property alias firstValue : rangeSlider.first.value
property alias secondValue : rangeSlider.second.value
property int step: 1
property int pivot: maxValue/2
Row {
anchors.fill: parent
Text {
width: parent.width * 0.15
height: parent.height
text: rangeSlider.first.value.toFixed(0)
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
}
RangeSlider {
id: rangeSlider
width: parent.width * 0.7
height: parent.height
from: minValue
to: maxValue
stepSize: step
snapMode: RangeSlider.SnapAlways
// binding loop here
first.value: first.value > pivot ? pivot : first.value
second.value: second.value < pivot ? pivot : second.value
}
Text {
width: parent.width * 0.15
height: parent.height
text : rangeSlider.second.value.toFixed(0)
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
}
}
}main.qml
import QtQuick 2.12
import QtQuick.Window 2.12
Window {
visible: true
width: 640
height: 480
RangeSliderFixed {
anchors.fill: parent
}
}当然,当值超过支点时会有绑定循环,但我对QML非常陌生,我不知道如何避免这种情况。
发布于 2020-12-09 15:49:16
移除:
// binding loop here
first.value: first.value > pivot ? pivot : first.value
second.value: second.value < pivot ? pivot : second.value增加以下内容:
first.onMove: {
if(first.value > pivot)
first.value = pivot;
}第二滑块相同
https://stackoverflow.com/questions/62023187
复制相似问题