PDA

View Full Version : Access parent property from repeater



c1223
27th November 2014, 21:47
Not entirely sure how to do this but:


import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Window 2.0
import QtQuick.Controls.Styles 1.2


ApplicationWindow {
id: theGui
property int appHeight: theGui.height
objectName: "mainWindow"
visible: true
visibility: "Maximized"
title: qsTr("Map")

Repeater {
id: mapRepeater
model: mapModel
Rectangle { width: xSize * model.modelData.scale; height: ySize * model.modelData.scale
color: ((xIndex % 2 == 1 && yIndex % 2 == 0) || (xIndex % 2 == 0 && yIndex % 2 == 1)) && (xIndex < 90) ? "white" : "black"
x: xPos * model.modelData.scale
y: yPos * model.modelData.scale
Text { text: (yIndex == 10 || xIndex == 14) ? "" : "(" + xIndex + ", " + yIndex + ")"
anchors.right: parent.right
anchors.top: parent.top
font.pointSize: 25 * model.modelData.scale
color: (xIndex % 2 == 1 && yIndex % 2 == 0) || (xIndex % 2 == 0 && yIndex % 2 == 1) ? "black" : "white"
}
}
}


}
}


From the rectangle component of the Repeater how would I access the "ApplicationWindow" height (i.e. appHeight). I tried with global variables (Qt.appHeight) but couldn't get that to work.

Essentially I want the rectangle to be able to access the dimensions of the ApplicationWindow.

Thanks

wysota
27th November 2014, 22:07
theGui.height

c1223
27th November 2014, 22:31
It returns "0". But the window is clearly larger than that.

anda_skoa
28th November 2014, 06:11
Have you tried with only one child of ApplicationWindow?

Say and Item that fills the window and having the Repeater inside it?

The way the ApplicationWindow is layouted it is designed for only one content item, but your repeater currently adds several.

Cheers,
_