0

In this qml code:

Component {      
  id: userdelegate
  PictureBox {
    ...
    icon: model.icon
    icon.heigth: 50
  }
}

PictureBox comes from the PictureBox.qml system file in this way:

...
Image {
  id: icon
  ...
  width: parent.width; height: 150
}

Running qml, I have the error in the title. I need to use PictureBox.qml, but I can't change it. How can I override default height value for PictureBox.qml icon?

Tarod
  • 6,732
  • 5
  • 44
  • 50
cloc3
  • 21
  • 2
  • I think the only way is using [aliases](http://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html#property-attributes). But you said you cannot change PictureBox.qml :-O – Tarod Sep 02 '16 at 07:48
  • I don't see an `icon` property anywhere in that code ("`PictureBox.qml`"). Can you post code that's actually relevant for the question? – Mitch Sep 02 '16 at 11:41
  • @Mitch: icon is the id of Image element. – cloc3 Sep 02 '16 at 16:01
  • @cloc3 `Image` doesn't have an `icon` property. You'll have trouble getting a correct answer if your question is incomplete. – Mitch Sep 02 '16 at 16:06
  • ok. This was my mystake. so I need to access the height property of Image element by id. how may i do? – cloc3 Sep 02 '16 at 16:24

1 Answers1

0

You can try to bypass QML's scoping rules by traversing Item children until you can find the Image and manipulate it directly. It's possible it could break in the future, but item.toString() gives you something useful:

item.toString() -> "QQuickImage(0x114054350)"

So, you can try something like this (not tested):

function findItemOfType(type, item) {
    if (item.toString().indexOf(type) != -1) {
        return child;
    }
    for (var i=0;i < children.length;++i) {
        var child = children[i];
        var result = findItemOfType(type, child.children);
        if (result != null) {
            return result;
        }
    }
    return null;
}

Using it like this:

findItemOfType("QQuickImage", pictureBoxId);
David K. Hess
  • 16,632
  • 2
  • 49
  • 73