'QML list of images not visible
I have not worked with QML lists much, but I have a QML parent Item that needs to draw a list of little tile images.
Whenever a QML Image is taken out of the list it is viewable but not while in the list.
(No compile-time or runtime warning or errors in either case)
Displays okay:
Item {
id : player_health
Image {
z:2;
height: 26;
width: 19;
x: 50;
y: 50;
source:"resources/gameplay/square_pink.png"
}
}
Does not display (neither of these images):
Item {
id : player_health
property list<Image> bars: [
Image { z:2; height: 26; width: 19; x: 50; y:50; source: "resources/gameplay/square_pink.png"},
Image { z:2; height: 26; width: 19; x: 50; y:50; source: "resources/gameplay/square_blue.png"}
]
}
I would like the images in the list to be visible but can't find a way to do it via a list.
Solution 1:[1]
Item {
id : player_health
Grid {
rows: 5; columns: 1; spacing: 10
Repeater { model: 5
Image { z:2; height: 26; width: 19; x: 50; y:50; source:"resources/gameplay/square_pink.png" }
}
}
Solution 2:[2]
What you created is a property list with Image types. Since this is only a property it won't be shown unless you create them.
One way would be to contain them in Components within the list and a Loader would be able to create them. But I guess that wasn't your intention based on the recent answers.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Willeman |
| Solution 2 | Tamás Grábler |
