在另一个鼠标区域QML / QT下使用滑块

时间:2015-11-02 10:23:24

标签: qml qt5 qtquick2

我正在Qt中设计一个UI界面,其中一个页面可以在视图之间滑动。我在整个屏幕中定义了一个SwipeArea区域(我在另一个QML文件中定义了MouseArea),以便能够在页面之间滑动,并将属性propagateComposedEvents设置为{ {1}}这样我就可以在页面之间滑动,并且仍然可以点击所有按钮。

使用true时出现问题。显然它无法获取这些鼠标事件,我无法与它进行交互,因为当我点击屏幕时它启动了滑动处理程序。我怎么能解决这个问题?

这是我定义Slider代码的地方:

SwipeArea.qml

以下是我使用它的import QtQuick 2.0 MouseArea { property point origin property bool ready: false signal move(int x, int y) signal swipe(string direction) propagateComposedEvents: true onPressed: { drag.axis = Drag.XAndYAxis origin = Qt.point(mouse.x, mouse.y) } onPositionChanged: { switch (drag.axis) { case Drag.XAndYAxis: if (Math.abs(mouse.x - origin.x) > 16) { drag.axis = Drag.XAxis } else if (Math.abs(mouse.y - origin.y) > 16) { drag.axis = Drag.YAxis } break case Drag.XAxis: move(mouse.x - origin.x, 0) break case Drag.YAxis: move(0, mouse.y - origin.y) break } } onReleased: { switch (drag.axis) { case Drag.XAndYAxis: canceled(mouse) break case Drag.XAxis: swipe(mouse.x - origin.x < 0 ? "left" : "right") break case Drag.YAxis: swipe(mouse.y - origin.y < 0 ? "up" : "down") break } } }

main.qml

添加我的滑块代码可能很重要:

Item {
        id: content
        width: root.width * itemDataLength
        height:parent.height

        property double k: (content.width - root.width) / (img.width - root.width)

        Repeater {
            id:repeater
            model: itemDataLength
            width:parent.width
            height:parent.height

            Loader{
                id:loader
                width:parent.width / 2
                x: root.width * index
                height:parent.height
                source:loaderItems[index]

            }
        }
    }

 SwipeArea {
        id: mouse
        anchors.fill: parent
        onMove: {
            content.x = (-root.width * currentIndex) + x
        }
        onSwipe: {

            switch (direction) {
            case "left":
                if (currentIndex === itemDataLength - 1) {
                    currentIndexChanged()
                }
                else {
                    currentIndex++
                }
                break
            case "right":
                if (currentIndex === 0) {
                    currentIndexChanged()
                }
                else {
                    currentIndex--
                }
                break
            }
        }
        onCanceled: {
            currentIndexChanged()
        }
    }

感谢您的帮助或意见,并提前感谢您!

0 个答案:

没有答案