gpt4 book ai didi

qt - 在布局 QML 中使用 Loader 对象

转载 作者:行者123 更新时间:2023-12-04 13:06:57 25 4
gpt4 key购买 nike

我想以这种形式在 ColumnLayout 对象中使用加载器对象:

Item{
width: 500
height: 300
focus: true
Keys.onLeftPressed: state = "matrix"
ColumnLayout{
id: panel
anchors.fill: parent

RowLayout{
Layout.minimumHeight: 30

Text {
Layout.fillWidth: true
text: "some"
}
Slider{
Layout.fillWidth: true
}
Button {
text: "otro"
}
}
Loader {
id: load
Layout.fillWidth: true
height: 30
width: 30
}
}
states: [
State {
name: "matrix"
PropertyChanges {
target: load
sourceComponent: tab

}
}
]
Component {
id:tab
Rectangle {
color: "red"
height: 30
width: 30
}
}
}

我使用键事件来更改状态属性,但“选项卡”组件不会加载到根项目中。
任何人都可以帮我解决这个问题吗?

最佳答案

Loader 不能有 layout.fillWidth。它必须在组件加载时设置:

Item{
width: 500
height: 300
focus: true
Keys.onLeftPressed: state = "matrix"
ColumnLayout{
id: panel
anchors.fill: parent

RowLayout{
Layout.minimumHeight: 30

Text {
Layout.fillWidth: true
text: "some"
}
Slider{
Layout.fillWidth: true
}
Button {
text: "otro"
}
}
Loader { id: load } // no property here
}
states: [
State {
name: "matrix"
PropertyChanges {
target: load
sourceComponent: tab;
Layout.fillWidth: true; // the layout is set here
}
}
]
Component {
id:tab
Rectangle {
color: "red"
width:30
height:30;
}
}
}

关于qt - 在布局 QML 中使用 Loader 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21324202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com