如何在QML中拖动/滑动元素而不更改其x,y位置?

时间:2013-07-15 10:48:06

标签: qt slider qml

我正在开发一个UI,我需要在任何智能手机中实现拖动状态栏的类似效果。

这应该在点击时向下滑动元素(这意味着它的高度增加)

我尝试使用以下代码来获取元素

的“NO x,y值更改”
MouseArea{
    id : zone2MouseArea
    anchors.fill : parent

    drag.target: zone2ID
    drag.axis: Drag.YAxis
    drag.minimumY: 0
    drag.maximumY: 0.1

}

和onYChanged()我增加了身高。

然而,这不足以满足我的要求。我需要滑动元素,改变它的高度视图,而不改变它的x,y值

1 个答案:

答案 0 :(得分:3)

我做了一个基本的例子。希望能帮助到你。截至目前我没有IDE,所以请检查语法错误

import QtQuick 1.1

Rectangle
{
    width: 560
    height: 560
    color: "blue"

    Rectangle
    {
       id: slider
       width: parent.width
       height: parent.height
       y: - parent.height * .90
       color: "yellow"

       property bool isAtTop: true

       Behavior on y { NumberAnimation { duration: 300 } }

       Text
       {
           text: qsTr("12:34 PM")
           anchors.bottom: parent.bottom
           color: "black"
       }

       Text
       {
           text: qsTr("Battery | Wifi | Updates")
           anchors.centerIn: parent
           color: "black"
           font.pixelSize: 25
       }

       MouseArea
       {
           id: draggingMouse
           anchors.fill : parent
           drag.target: parent
           drag.axis: Drag.YAxis
           drag.minimumY: - parent.height * .90
           drag.maximumY: 0

           onReleased:
           {
               if ( true == slider.isAtTop )
               {
                   if( slider.y < - parent.height * .80 )
                       slider.y = - parent.height * .90
                   else
                   {
                       slider.y = 0
                       slider.isAtTop = false
                   }
               }

               else
               {
                   if( slider.y < - parent.height * .20 )
                   {
                       slider.y = - parent.height * .90
                       slider.isAtTop = true
                   }

                   else
                   {
                       slider.y = 0
                   }
               }

           }
       }
    }
}