on xenial help sign in
Pass index using a property, because it gets lost through the Loader.
d6aae77Michał Sawicz
qml/Components/BaseCarouselDelegate.qml+3
@@ -28,6 +28,9 @@ Item {
28 /// True if this item is currently "focused" in the carousel.
28 /// True if this item is currently "focused" in the carousel.
29 property bool explicitlyScaled
29 property bool explicitlyScaled
30
30
31+ /// Model index for this delegate.
32+ property int index
33+
31 /// Model data for this delegate.
34 /// Model data for this delegate.
32 property var model
35 property var model
33
36
qml/Components/Carousel.qml+1−1
@@ -306,8 +306,8 @@ Item {
306 }
306 }
307
307
308 onLoaded: {
308 onLoaded: {
309− item.objectName = Qt.binding(function() { return "carouselDelegate" + index; });
310 item.explicitlyScaled = Qt.binding(function() { return explicitlyScaled; });
309 item.explicitlyScaled = Qt.binding(function() { return explicitlyScaled; });
310+ item.index = Qt.binding(function() { return index; });
311 item.model = Qt.binding(function() { return model; });
311 item.model = Qt.binding(function() { return model; });
312 }
312 }
313
313
qml/Dash/CardCarousel.qml+3−1
@@ -48,14 +48,16 @@ DashRenderer {
48
48
49 property bool explicitlyScaled
49 property bool explicitlyScaled
50 property var model
50 property var model
51+ property int index
51 enabled: false
52 enabled: false
52
53
54+ objectName: "carouselDelegate" + index
55+
53 function clicked() { cardCarousel.clicked(index, model.result) }
56 function clicked() { cardCarousel.clicked(index, model.result) }
54 function pressAndHold() { cardCarousel.pressAndHold(index, model.result) }
57 function pressAndHold() { cardCarousel.pressAndHold(index, model.result) }
55
58
56 sourceComponent: cardTool.cardComponent
59 sourceComponent: cardTool.cardComponent
57 onLoaded: {
60 onLoaded: {
58− item.objectName = "carouselDelegate" + index;
59 item.fixedHeaderHeight = Qt.binding(function() { return carousel.headerHeight; });
61 item.fixedHeaderHeight = Qt.binding(function() { return carousel.headerHeight; });
60 item.height = Qt.binding(function() { return cardTool.cardHeight; });
62 item.height = Qt.binding(function() { return cardTool.cardHeight; });
61 item.cardData = Qt.binding(function() { return model; });
63 item.cardData = Qt.binding(function() { return model; });
tests/qmltests/Components/tst_Carousel.qml+2
@@ -32,6 +32,8 @@ Item {
32 property int destroyedDelegates: 0
32 property int destroyedDelegates: 0
33
33
34 itemComponent: BaseCarouselDelegate {
34 itemComponent: BaseCarouselDelegate {
35+ objectName: "carouselDelegate" + index
36+
35 Rectangle {
37 Rectangle {
36 anchors.fill: parent
38 anchors.fill: parent
37 border.color: "black"
39 border.color: "black"