<?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[Accessing SliderStyle&#x27;s components to change opacity]]></title><description><![CDATA[<p dir="auto">Hi everyone, I'm trying to customize a Slider in order to make the handle visible only when the user is hovering above the slider. So I tryed using states and PorpertyChanges to change the opacity, but I can't target the handle. I'm guessing it's because it's no a direct sub-component of the root but more like a component of a property.</p>
<p dir="auto">Here is my code (a bit simplified) :</p>
<pre><code>import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4

Slider {
    anchors {
        fill: parent
        margins: 10;
    }
    id: slider
    value: 0.5
    style : SliderStyle {
        groove: Rectangle {
            id: background
            /* ... */
        }
        handle: Rectangle {
            id: handle
            /* ... */
            opacity: 0.0
        }
    }

    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        onEntered: { slider.state = "hovered" }
        onExited: { slider.state = "" }
    }

    states: [
        State {
            name: "hovered"
            PropertyChanges { target: handle ; opacity: 1.0 } // This part does not works
        }
    ]
}
</code></pre>
<p dir="auto">When rendering it with qmlscene, I get the error :</p>
<pre><code>file.qml:68: ReferenceError: handle is not defined
</code></pre>
<p dir="auto">Can anyone help me change the opacity of the handle ? Thx</p>
]]></description><link>https://forum.qt.io/topic/83291/accessing-sliderstyle-s-components-to-change-opacity</link><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Nov 2026 06:02:12 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/83291.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Sep 2017 15:15:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Accessing SliderStyle&#x27;s components to change opacity on Fri, 15 Sep 2017 09:01:49 GMT]]></title><description><![CDATA[<p dir="auto">OK<br />
found a solution, for those interested, it's based on the fact that maybe the root item can't access the handle but the handle on the other hand can access the root item. So I created a binding between handle's state and slider's state :</p>
<pre><code>Slider {
    anchors {
        fill: parent
        margins: 10;
    }
    id: slider
    value: 0.5
    style : SliderStyle {
        groove: Rectangle {
            id: background
            /* ... */
        }
        handle: Rectangle {
            id: handle
            /* ... */
            opacity: 0.0
            // Bind slider's state and handle's state
            state: slider.state == "hovered" ? "hovered" : ""

             states : [
                 State {
                     name: "hovered"
                     PropertyChanges { target: handle ; opacity: 1.0 }
                 }
             ]
        }
    }

    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        onEntered: { slider.state = "hovered" }
        onExited: { slider.state = "" }
    }

    states: [ State { name: "hovered" } ]
}
</code></pre>
]]></description><link>https://forum.qt.io/post/415449</link><guid isPermaLink="true">https://forum.qt.io/post/415449</guid><dc:creator><![CDATA[MoaMoaK]]></dc:creator><pubDate>Fri, 15 Sep 2017 09:01:49 GMT</pubDate></item></channel></rss>