首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有枢轴值的QML RangeSlider

具有枢轴值的QML RangeSlider
EN

Stack Overflow用户
提问于 2020-05-26 13:24:42
回答 1查看 234关注 0票数 0

我在玩RangeSlider,我正在尝试创建一个支点值,其中第一个不能超过这个值,第二个不能低于这个值。

RangeSliderFixed.qml

代码语言:javascript
复制
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

代码语言:javascript
复制
import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    visible: true
    width: 640
    height: 480

    RangeSliderFixed {
        anchors.fill: parent
    }
}

当然,当值超过支点时会有绑定循环,但我对QML非常陌生,我不知道如何避免这种情况。

EN

回答 1

Stack Overflow用户

发布于 2020-12-09 15:49:16

移除:

代码语言:javascript
复制
 // binding loop here
        first.value: first.value > pivot ? pivot : first.value
        second.value: second.value < pivot ? pivot : second.value

增加以下内容:

代码语言:javascript
复制
first.onMove: {
if(first.value > pivot)
    first.value = pivot;
}

第二滑块相同

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62023187

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档