qt - QML Column 不会自动设置子对象宽度
问题描述
我正在尝试使用列和行来布置我的用户界面。
import QtQuick 2.6
import QtQuick.Window 2.2
Window{
height: 200
width : 300
Row{
height: parent.height
width: parent.width
Column{
width: parent.width / 2
height: parent.height
Text{
text: "Hello World!"
}
Text{
wrapMode: Text.WordWrap
text: "This text is so long that it doesn't fit inside the column on a single line, but I'd assume that column sets child object width."
}
Rectangle{
height: parent.height - y
width: parent.width
color: "#aa0000aa"
Text{
anchors.bottom: parent.bottom
text: "Hello2"
}
}
}
Column{
height: parent.height
width: parent.width / 2
Text{
text: "Hello1"
}
Rectangle{
height: parent.height - y
color: "#4c00aa00"
width: parent.width
Text{
anchors.bottom: parent.bottom
text: "Hello2"
}
}
}
}
}
可以看出,文本对象的宽度没有绑定到它的父对象。
由于某种原因,我无法使用布局 qml 对象,因为它们锁定了我的目标系统。
我只需要在我的代码中添加一些内容,width: parent.width
还是有更好的方法来解决这个问题?
解决方案
推荐阅读
- android - 外部库在发布 apk android 中不起作用
- laravel - 具有静态字段值的 Elasticsearch multi_query
- javascript - 使用 Google 跟踪代码管理器创建自定义 cookie 的最佳方法是什么?
- java - 更新 Map 的 Map 值
- firebase - Firebase 基于角色的访问
- haskell - QuickCheck 中的相关收缩
- git - 文件系统已损坏:表示损坏 格式错误的表示标头
- sqlite - Python Pandas 到 sqlite
- node.js - Python中的Nodejs Crypto RSA_NO_PADDING等价物?
- c# - 使用 newtonsoft 获取两个 JSON 对象的差异