PDA

View Full Version : overriding a property fixed by an external component



cloc3
3rd September 2016, 11:05
I want to ovverride the height value for the image defined in a external PictureBox.qml file:



import QtQuick 2.0

FocusScope {
id: container
...
Column {
id: column
...
Image {
id: icon
width: parent.width; height: 150
...


this code is called in Main.qml in this way:



Component {
id: userDelegate

PictureBox {
???
...


how can I override height value for the Image element, without touching PictureBox.qml code?

Dharkael
3rd September 2016, 15:33
You can´t access internal properties in the children of the components because of scope, the tool provided by QML to access internal properties are "property aliases", that way your PictureBox.qml must contain a single line in the root element with the structure: "property alias name: id.property"


import QtQuick 2.0

FocusScope {
id: container
propery alias iconHeight: icon.height //alias
...
Column {
id: column
...
Image {
id: icon
width: parent.width; height: 150
...

and your Main would access that property like this:


Component {
id: userDelegate

PictureBox {
iconHeight: 100
...