【发布时间】:2017-11-13 07:15:16
【问题描述】:
有一个传感器元件的代码。它就像其他传感器类型元素的基类:
Rectangle {
property real value: 0
property alias imageWidth: image.width
property alias imageSource: image.source
property alias displayWidth: display.width
width: Math.max(image.width, display.width)
height: image.height + display.height
border.width: 1
Rectangle {
id: display
width: 40
height: 20
border.width: 1
color: "lightgreen"
Text {
anchors.centerIn: parent
text: value
font.pixelSize: parent.width * 0.3;
}
}
Image {
id: image
width: display.width * 0.5
anchors.top: display.bottom
anchors.horizontalCenter: display.horizontalCenter
source: "qrc:/images/temperature.png"
fillMode: Image.PreserveAspectFit
}
}
如果我将传感器放在Column 中,它们的位置是正确的。
派生类型的实现-Pressure:
Item {
Sensor {
imageSource: "qrc:/images/pressure.png"
imageWidth: displayWidth * 0.4
}
}
但如果我将Pressure 传感器放在Row 或Column 中,所有传感器就会相互重叠。
Column {
spacing: 10
Pressure {}
Pressure {}
Pressure {}
}
Pressures and Sensors comparison (image)
你能解释一下它有什么问题吗?
【问题讨论】:
标签: qt user-interface qml qtquick2