2

我有一个 QML Row 元素,里面有一个 Repeater,声明如下:

Row {
    anchors.fill: parent

    Repeater {
        ...
    }

    Rectangle {
        height: 30
        color: "black"
    }
}

我想让 Rectangle 元素将他的宽度从中继器的右侧扩展到父行的末尾。我怎样才能做到这一点?

更新 在此处输入图像描述

4

2 回答 2

1

这应该有效:

Row {
    anchors.fill: parent

    Repeater {
        id: repeater
        ...
    }

    Rectangle {
        height: 30
        color: "black"
        width: parent.width - repeater.width
    }
}
于 2012-06-24T08:39:00.670 回答
0

我使用下面的代码解决了因为中继器宽度不会自动设置为等于所有项目的总宽度总和

Repeater {
    id: repeater
    ...
    onItemAdded: {
        repeater.width += item.width
    }
}
于 2012-06-24T10:46:47.240 回答