qt - 无法将双精度分配给 QQuickAnchorLine
问题描述
我想将底部图像放在顶部图像上方。但是在向锚添加偏移量后,我得到了这个错误:
qrc:/Template.qml:21:22: Unable to assign double to QQuickAnchorLine
在这条线上添加 20 像素的偏移量后:
anchors.top: top_bg.bottom-20
如何使用锚点作为参考点来偏移项目?
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.11
import QtQuick.Dialogs 1.0
import QtQuick.Controls.Material 2.3
Item {
id: root
Image {
id: top_bg
source: "qrc:/images/top_bg.png"
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: root.height*0.33
fillMode: Image.PreserveAspectCrop
}
Image {
id: map_bg
source: "qrc:/images/map_bg.png"
anchors.top: top_bg.bottom-20
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
fillMode: Image.PreserveAspectCrop
}
}
解决方案
锚点不是数字位置,而是相对于项目的位置,不能添加或减去它们,在您的情况下,您应该使用属性y
和height
:
Image {
id: map_bg
source: "qrc:/images/map_bg.png"
y: top_bg.y + top_bg.height - 20 // <---
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
fillMode: Image.PreserveAspectCrop
}
另一种选择是使用边距:
Image {
id: map_bg
source: "qrc:/images/map_bg.png"
anchors.top: top_bg.bottom
anchors.topMargin: -20
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
fillMode: Image.PreserveAspectCrop
}
推荐阅读
- c# - 将 JSON 更改为 JSON 数组(例如 [1,2,3])或更改反序列化类型,使其正常
- mongoose - 收到错误“throw new mongoose.Error.MissingSchemaError(name); MissingSchemaError:”
- scala - 如何在数据框中附加列值
- label - 自定义工具提示内容@ngx-charts | 角2+ | 打字稿
- python - 如何通过 cython 将 MPI 通信器从 python 传递到 C?
- database - Laravel 单元测试独立数据库
- json - JSON Schema 仅针对数组的第一个元素报告错误
- asp.net - 发布集合 - 在表格行上添加类时为空/null
- node.js - 在 conda 环境中安装 nodeJS
- r - 如何重命名列中某个值之前出现的 n 行?