import QtQuick 2.0 Item { id: rectdrag property int xPosition : (barPoint.x) / (barBackground_Middle.width)*(sliderpartnum) property int enterValue onEnterValueChanged: { barPoint.x = enterValue //quanshaoying } property int exportValue : barPoint.x property alias barBackgroundMiddlewidth:barBackground_Middle.width property alias barBackgroundLeftSource: barBackground_Left.source property alias barBackgroundMiddleSource: barBackground_Middle.source property alias barBackgroundRightSource: barBackground_Right.source property alias barBlueLeftSource: barBlue_Left.source property alias barBlueMiddleSource: barBlue_Middle.source property alias barBlueRightSource: barBlue_Right.source property alias barPointSource: barPoint.source property int sliderpartnum:100 property double add : barBackground_Middle.width/sliderpartnum property alias barPointmouseopacity:barPointmouse.opacity property alias barBackgroundMiddlemouse:barBackground_Middlemouse.opacity signal clickSlider(); signal dragBarPoint(); width: barBackground_Middle.width+barBackground_Left.width+barBackground_Right.width height: barPoint.height Image{ id:barBackground_Left anchors.verticalCenter: parent.verticalCenter source: "../../../../images/Slider/Slider_Background_Left.png" HMIMouseArea{ id:barBackground_Leftmouse anchors.fill: parent onClicked: {barPoint.x=0}} } Image{ id:barBackground_Middle width:100 anchors.left: barBackground_Left.right anchors.verticalCenter: parent.verticalCenter source: "../../../../images/Slider/Slider_Background_Middle.png" HMIMouseArea{ id:barBackground_Middlemouse anchors.fill: parent onClicked: { barPoint.x=add*((mouseX-mouseX%add)/add+((mouseX%add)/add>0.5?1:0)) clickSlider(); } } } Image{ id:barBackground_Right anchors.left:barBackground_Middle.right anchors.verticalCenter: parent.verticalCenter source: "../../../../images/Slider/Slider_Background_Right.png" HMIMouseArea{ id:barBackground_Rightmouse anchors.fill: parent onClicked: {barPoint.x=rectdrag.width-barBlue_Right.width-barBlue_Left.width}} } Image{ id:barBlue_Left anchors.left:barBackground_Left.left anchors.verticalCenter: parent.verticalCenter source: "../../../../images/Slider/Slider_Blue_Left.png" } Image{ id:barBlue_Middle width: barPoint.x anchors.left:barBlue_Left.right anchors.verticalCenter: parent.verticalCenter source: "../../../../images/Slider/Slider_Blue_Middle.png" } Image{ id:barBlue_Right anchors.left:barPoint.horizontalCenter anchors.verticalCenter: barBlue_Middle.verticalCenter source: "../../../../images/Slider/Slider_Blue_Right.png" } Image{ id:barPoint x:enterValue anchors.verticalCenter: parent.verticalCenter source: "../../../../images/Slider/Slider_Pointer.png" onXChanged: { exportValue = barPoint.x } HMIMouseArea{ id:barPointmouse x: 0 y: 0 anchors.rightMargin: 0 anchors.bottomMargin: 0 anchors.leftMargin: 0 anchors.topMargin: 0 anchors.fill: parent drag.target: barPoint drag.axis: "XAxis" drag.minimumX: 0 drag.maximumX:rectdrag.width-barBlue_Right.width-barBlue_Left.width onMouseXChanged: { barPoint.x =add*((barPoint.x-barPoint.x%add)/add+((barPoint.x%add)/add>0.5?1:0)); enterValue = barPoint.x // dragBarPoint(); } onExited: { dragBarPoint(); //by quanshaoying } } } }