<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Qml-presentation-system and mouse interaction with a SlideSwitch]]></title><description><![CDATA[<p dir="auto">Hi everyone</p>
<p dir="auto">I'm preparing a speech with the qml-presentation-system.<br />
On one slide I have add a SlideSwitch.<br />
The SlideSwitch appears as expected but I can't move the handle.</p>
<p dir="auto">It seems that the MouseArea works perfect and receives the mouse click.<br />
But the drag is not working.<br />
The code below is working perfectly when I use qmlscene but integrated in the qml-presentation-system it is not working.<br />
Any ideas?</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/import">@<bdi>import</bdi></a> QtQuick 2.0</p>
<p dir="auto">/**<br />
This item provides a secure slideswitch. A SlideSwitch is a switch that can<br />
not be pressed accidentally. The user has to slide to knob to the other side<br />
to toggle.<br />
*/<br />
Item {<br />
id: slideswitch<br />
property alias on: button.on<br />
signal toggled(bool on)</p>
<pre><code>Rectangle {
    id: background
    property bool hover: false
    color: "#2d2d2d"
    border.width: 4
    border.color: "white"
    radius: 8
    width: parent.width
    height: parent.height

    anchors.fill: parent
}

Rectangle {
    id: button
    property bool on: false

    height: background.height - 2*background.border.width
    width: (background.width / 2)-10
    color: button.on ? "grey" : "#2d2d2d"
    border.width: background.border.width
    border.color: "white"
    radius: 4
    x:background.border.width
    y:background.border.width

    Text
    {
        id: label
        anchors.fill: parent
        text: button.on ? "DSP" : "ARM"
        font.family: "OpenSymbol"
        font.pixelSize: 27
        font.bold: true
        color: button.on ? "#2d2d2d" : "grey"
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment:  Text.AlignVCenter
    }

    MouseArea {
        id: bla
        anchors.fill: parent
        drag.target: parent
        drag.axis: Drag.XAxis
        drag.minimumX: background.border.width
        drag.maximumX: background.width - button.width - background.border.width

        onReleased: {
            console.log("Greatings from below. ButtonX: "+button.x+"drag.max: "+drag.maximumX)

            if(button.x &gt; ((drag.maximumX) / 2)) {
                slideswitch.state = ""
                slideswitch.state = "on"
                toggled(true)
            }
            else {
                slideswitch.state = ""
                slideswitch.state = "off"
                toggled(false)
            }
        }
    }
}

// using states to differentiate between "on" and "off"
states: [
    State {
        name: "on"
        PropertyChanges {
            target: button
            x: background.width - button.width - background.border.width
            on: true
        }
    },
    State {
        name: "off"
        PropertyChanges {
            target: button
            x: background.border.width
            on: false
        }
    }
]

transitions: Transition {
    NumberAnimation {
        properties: "x"
        duration: 400
        easing.type: Easing.OutQuad
    }
}
</code></pre>
<p dir="auto">}@</p>
]]></description><link>https://forum.qt.io/topic/31085/qml-presentation-system-and-mouse-interaction-with-a-slideswitch</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 08:41:40 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/31085.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Aug 2013 14:05:34 GMT</pubDate><ttl>60</ttl></channel></rss>