
Originally Posted by
isdes
I have tried the malcom2073's if-example on Qt 4.7.0 and it works as expected. However on 4.7.2 the model variables are not visible to the textComponent and boolComponent delegates:
TestDelegates.qml:39: ReferenceError: Can't find variable: value
TestDelegates.qml:39: ReferenceError: Can't find variable: value
TestDelegates.qml:39: ReferenceError: Can't find variable: value
TestDelegates.qml:39: ReferenceError: Can't find variable: value
To copy to clipboard, switch view to plain text mode
I have also tried to change the name of the variable in case it may be reserved keyword with the same result.
Does anyone have an idea what has changed from 4.7.0 to 4.7.2 in this topic and how to update this example to work?
Regards,
Darek
Same here with 4.7.2 - but found another solution - one Component with a conditional state switch:
import QtQuick 1.0
Rectangle {
width: 640
height: 480
ListView {
id: view
anchors.fill: parent
model: model
delegate: delegate
}
ListModel {
id: model
ListElement {
name: "text"
value: "hello"
asd: 't'
}
ListElement {
name: "bool"
value: true
qwe: 'b'
}
ListElement {
name: "bool"
value: false
qwe: 'b'
}
ListElement {
name: "text"
value: "world"
asd: 't'
}
}
Component {
id: delegate
Rectangle {
id: wgt
property alias r1_visible: r1.visible
property alias r2_visible: r2.visible
height: 20
state: name == "text" ? "s1" : "s2"
Rectangle {
id: r1
Text {
id: c1
text: asd + " " + value
}
}
Rectangle {
id: r2
Text {
id: c2
text: qwe + " " + (value ? "[X]" : "[ ] ")
}
}
states: [
State {
name: "s1"
PropertyChanges {
target: wgt
r1_visible: true
r2_visible: false
}
},
State {
name: "s2"
PropertyChanges {
target: wgt
r1_visible: false
r2_visible: true
}
}
]
}
}
}
import QtQuick 1.0
Rectangle {
width: 640
height: 480
ListView {
id: view
anchors.fill: parent
model: model
delegate: delegate
}
ListModel {
id: model
ListElement {
name: "text"
value: "hello"
asd: 't'
}
ListElement {
name: "bool"
value: true
qwe: 'b'
}
ListElement {
name: "bool"
value: false
qwe: 'b'
}
ListElement {
name: "text"
value: "world"
asd: 't'
}
}
Component {
id: delegate
Rectangle {
id: wgt
property alias r1_visible: r1.visible
property alias r2_visible: r2.visible
height: 20
state: name == "text" ? "s1" : "s2"
Rectangle {
id: r1
Text {
id: c1
text: asd + " " + value
}
}
Rectangle {
id: r2
Text {
id: c2
text: qwe + " " + (value ? "[X]" : "[ ] ")
}
}
states: [
State {
name: "s1"
PropertyChanges {
target: wgt
r1_visible: true
r2_visible: false
}
},
State {
name: "s2"
PropertyChanges {
target: wgt
r1_visible: false
r2_visible: true
}
}
]
}
}
}
To copy to clipboard, switch view to plain text mode
It still feels a bit hacky and I think that this is a bug in 4.7.2 but everything looks as expected
t hello
b [X]
b [ ]
t world
t hello
b [X]
b [ ]
t world
To copy to clipboard, switch view to plain text mode
and even no warning about missing properties (asd/qwe)
Bookmarks