X doubles when z > 0
-
wrote on 5 Dec 2011, 10:30 last edited by
Hi folks, please see the code below:
@import QtQuick 1.1
Item{
id: containerwidth: 500 height: 500 Flow{ id: flow property int currentItem: -1 width: 300 height: 300 spacing: 5 Repeater{ id: repeater model: 3 Rectangle{ id: rect width: 60 height: 60 color: "red" states: State{ name: "active" when: flow.currentItem === index PropertyChanges{target: rect; height: 80; width: 80; color: "green"; z: 1} } } } } MouseArea{ anchors.fill: flow onClicked: flow.currentItem = container.getIndex(mouseX, mouseY) } function getIndex(x, y){ for(var i = 0; i < repeater.count; i++) console.log("index=" + i + ", x=" + flow.children[i].x + ", y=" + flow.children[i].y); for(var i = 0; i < repeater.count; i++) { if(x > flow.children[i].x && x < flow.children[i].x + flow.children[i].width) if(y > flow.children[i].y && y < flow.children[i].y + flow.children[i].height) return i; } return -1; }
}
@and it outputs when you click on some rect first time:
index=0, x=0, y=0
index=1, x=65, y=0
index=2, x=130, y=0and after the second time(after z was set):
index=0, x=0, y=0
index=1, x=150, y=0
index=2, x=0, y=0you can see that x has doubled its value after z was set and something strange has happened with the last item coordinates.
While I'm not actually bothering about the last item coordinates I want to know what happened with item's x after its z was set to non negative value.Thanks!
-
wrote on 5 Dec 2011, 10:40 last edited by
I don't know if it will correct your problem but either way it would be better to add an extra inactive state to make z equal to zero when not active:
@
states: [
State{
name: "active"
when: flow.currentItem === index
PropertyChanges{target: rect; height: 80; width: 80; color: "green"; z: 1}
},
State{
name: "inactive"
when: flow.currentItem !== index
PropertyChanges{target: rect; height: 60; width: 60; color: "green"; z: 0}
}
]
@ -
wrote on 5 Dec 2011, 10:49 last edited by
favoritas37, z is zero by default so there is no need to add an extra state since it is already in the default one.
-
wrote on 5 Dec 2011, 10:55 last edited by
Yeah but after making something active, how is it going to get inactive once again if you select something else? That is why i said that. Not for initialization.
-
wrote on 5 Dec 2011, 11:08 last edited by
it will be inactive when flow.currentItem changes. And it will be changed when click on other item. It would work quite good if there was no issue with the coordinates change.
-
wrote on 5 Dec 2011, 11:28 last edited by
Ok i see, indeed it is a weird problem...
Would you be interested in the following implementation?
@
import QtQuick 1.1Item{
id: containerwidth: 500 height: 500 MouseArea{ anchors.fill: parent onClicked: flow.currentItem = -1; } Flow{ id: flow property int currentItem: -1 width: 500 height: 500 spacing: 5 Repeater{ id: repeater width: 500 height: 500 model: 4 Rectangle{ id: rect width: 60 height: 60 color: "red" states: [ State{ name: "active" when: flow.currentItem === index PropertyChanges{target: rect; height: 80; width: 80; color: "green"; z: 1} }, State{ name: "inactive" when: flow.currentItem !== index PropertyChanges{target: rect; height: 60; width: 60; color: "red"; z: 0} } ] MouseArea{ anchors.fill: parent onClicked: flow.currentItem = index } } } }
}
@ -
wrote on 5 Dec 2011, 11:32 last edited by
It is actually only the part of the bigger problem. So I just want to understand what happens with coordinates.
7/7