QML fillWidth仅在调整大小时更新
我在以下代码中遇到Layout.fillWidth属性问题:QML fillWidth仅在调整大小时更新,qml,Qml,我在以下代码中遇到Layout.fillWidth属性问题: import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 import QtQuick.Controls.Material 2.0 RowLayout { spacing: 40 Rectangle { color:"#39c605" height:width Layout.fi
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls.Material 2.0
RowLayout {
spacing: 40
Rectangle {
color:"#39c605"
height:width
Layout.fillWidth: true
}
Rectangle {
color:"#39c605"
Layout.fillWidth: true
height:width
}
Rectangle {
color:"#39c605"
Layout.fillWidth: true
height:width
}
}
只有当我改变窗口的大小时,我才能看到矩形,但当应用程序启动时,它不可见
请帮我解决这个问题
加:
main.qml
QT 5.8请提供真实代码。在这段代码中,您没有为
RowLayout
定义大小,因此将不会显示任何内容。您还将高度
设置为宽度
,但在应用程序启动时,宽度为0<代码>布局将在所有组件都已初始化后执行其工作。您没有对布局本身设置大小调整策略。如果在布局上设置锚定。fill:true,会有什么行为?folibis,对不起,我添加了它。BaCaRoZzo,它是在父元素中设置的,因此第一个代码块定义了DataList
?您的布局在哪里?也许你想用StackLayout
代替StackView
?是的,这是数据列表,对不起。哦,这是我的错…是的,这应该是布局,谢谢
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls.Material 2.0
import "pages/"
ApplicationWindow {
id:mainWindows
visible: true
width:1280
height:720
title:qsTr("abc")
Material.theme: Material.Light
Material.accent: Material.LightGreen
Material.primary: Material.Blue
StackView {
id:homeView
anchors.fill: parent
initialItem:DataList{
}
}
}