首页 文章

无效的分组属性访问权限

提问于
浏览
0

在这个qml代码中:

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

PictureBox 以这种方式来自 PictureBox.qml 系统文件:

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

运行qml,我在 Headers 中有错误 . 我需要使用 PictureBox.qml ,但我无法改变它 . 如何覆盖 PictureBox.qml 图标的默认高度值?

1 回答

  • 0

    您可以尝试绕过QML 's scoping rules by traversing Item children until you can find the Image and manipulate it directly. It'可能会在未来中断,但 item.toString() 为您提供了一些有用的东西:

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

    所以,你可以尝试这样的东西(未测试):

    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;
    }
    

    像这样使用它:

    findItemOfType("QQuickImage", pictureBoxId);
    

相关问题