[Interest] React to signal only when at top of StackView
J-P Nurmi
jpnurmi at qt.io
Fri May 6 22:41:18 CEST 2016
> On 06 May 2016, at 22:27, Elvis Stansvik <elvstone at gmail.com> wrote:
>
> Hi all,
>
> I want that an item reacts to a certain signal only when it is at the
> top of a StackView, so I tried something like:
>
> Connections {
> // Below won't work:
> target: Stack.status === Stack.Active ? button : null
> //target: button // ..but this works
> onClicked: console.log("clicked")
> }
>
> That is, making the target of the connection null unless Stack.status
> == Stack.Active, but it seems it's not working.
>
> Full example below:
>
> import QtQuick 2.4
> import QtQuick.Controls 1.3
> import QtQuick.Window 2.2
>
> Window {
> id: window
> width: 500
> height: 500
> visible: true
>
> Column {
> Rectangle {
> width: 100
> height: 100
> color: "gray"
>
> MouseArea {
> id: button
> anchors.fill: parent
> Text {
> text: "Click Me"
> anchors.centerIn: parent
> }
> }
> }
>
> StackView {
> id: stackView
> width: 100
> height: 100
>
> initialItem: Rectangle {
> anchors.fill: parent
> color: "green"
> Connections {
> // Below won't work:
> target: Stack.status === Stack.Active ? button : null
> //target: button // ..but this works
> onClicked: console.log("clicked")
> }
> }
> }
> }
> }
>
> Anyone know what the problem might be? The item here is definitely
> active on the stack, since it's the initial (and only item).
>
Hi,
The Stack.status property must be attached to an item that is in a StackView. In the snippet above, it is attached to the Connections element. You can give the Rectangle element an id to be able to attach the property to it instead.
initialItem: Rectangle {
id: rect // <==
anchors.fill: parent
color: "green"
Connections {
target: rect.Stack.status === rect.Stack.Active ? button : null // <==
onClicked: console.log("clicked")
}
}
--
J-P Nurmi
More information about the Interest
mailing list