我在这里有几个问题,因为我是qml的新手。我有一个简单的界面,我希望滑块调整矩形的大小(最终将是svg图标)。图片下方的问题:
QML
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ColumnLayout {
anchors.fill: parent
Flow {
Layout.fillWidth: true
spacing: 10
Repeater {
model: 5
Rectangle {
id: delegateBackground
width: 200;
height: contentContainer.height + 10
border.width: 1
color: "lightgreen"
Item {
id: contentContainer
width: parent.width - 10
height: rowContainer.height
anchors.centerIn: delegateBackground
RowLayout {
id: rowContainer
width: parent.width
Rectangle {
id: icon
width: thumbnailsize.value
height: thumbnailsize.value
color: "steelblue"
Layout.alignment: Qt.AlignCenter
}
ComboBox {
id: selector
Layout.fillWidth: true
model: [ "Banana", "Apple", "Coconut" ]
Layout.alignment: Qt.AlignCenter
}
}
}
}
}
}
Slider {
id: thumbnailsize
from: 16
value: 48
to: 64
}
}
答案 0 :(得分:1)
// ...
// ...
Rectangle {
id: icon
Layout.preferredWidth: thumbnailsize.value
Layout.preferredHeight: thumbnailsize.value
// #### You can use width and height inside Layouts
// width: thumbnailsize.value
// height: thumbnailsize.value
color: "steelblue"
Layout.alignment: Qt.AlignCenter
}
// ...
// ..
滑块最大值错误
因此,如果您按照上述说明进行更改,此问题也将得到解决。
最小值:-
最小值
最大值:-
最大值
答案 1 :(得分:0)
是您想要的吗?
QML代码:
ColumnLayout {
anchors.fill: parent
Flow {
Layout.fillWidth: true
spacing: 10
Repeater {
model: 5
Rectangle {
id: delegateBackground
width: 200;
height: contentContainer.height + 10
border.width: 1
color: "lightgreen"
Item {
id: contentContainer
width: parent.width - 10
height: rowContainer.height
anchors.centerIn: delegateBackground
RowLayout {
id: rowContainer
anchors.centerIn: contentContainer
height: Math.max(iconContainer.height, selector.height)
Item{
id: iconContainer
width: contentContainer.width - selector.width
height: parent.height
Rectangle {
id: icon
width: thumbnailsize.value + selector.width > contentContainer.width ? contentContainer.width - selector.width : thumbnailsize.value
height: width
color: "steelblue"
anchors.centerIn: parent
}
}
ComboBox {
id: selector
Layout.fillWidth: true
model: [ "Banana", "Apple", "Coconut" ]
Layout.alignment: Qt.AlignCenter
}
}
}
}
}
}
Slider {
id: thumbnailsize
from: 16
value: 48
to: 64
}
}