任何类型的定位器都不适用于用户定义的元素
Any type of positioners doesn't work with user-defined element
有传感器元件的代码。它就像其他传感器类型元素的基础 class:
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)
你能解释一下它有什么问题吗?
哦,看来我自己找到答案了
Items
在派生 class 中像 Pressure
没有自己的宽度和高度。如果我删除 Item
,它会正常工作:
Sensor {
imageSource: "qrc:/images/pressure.png"
imageWidth: displayWidth * 0.4
}
有传感器元件的代码。它就像其他传感器类型元素的基础 class:
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)
你能解释一下它有什么问题吗?
哦,看来我自己找到答案了
Items
在派生 class 中像 Pressure
没有自己的宽度和高度。如果我删除 Item
,它会正常工作:
Sensor {
imageSource: "qrc:/images/pressure.png"
imageWidth: displayWidth * 0.4
}