Qt 调整QML行布局附加属性
我正在尝试一个简单的Qt 调整QML行布局附加属性,qt,qml,qtquick2,Qt,Qml,Qtquick2,我正在尝试一个简单的RowLayout矩形。(请参阅下面的代码。)当我尝试在Qt Creator中编译/运行此代码时,我得到: qrc:/main.qml:31不创建布局类型的对象 当我尝试使用Layout.minimumWidth:200或Layout{minimumWidth:200} Qt显示了第一个正在工作的窗体。我错过了什么 导入QtQuick 2.7 导入QtQuick.Controls 2.0 导入QtQuick.Layouts 1.3 应用程序窗口{ id:窗口 标题:“RB3J
RowLayout
矩形。(请参阅下面的代码。)当我尝试在Qt Creator中编译/运行此代码时,我得到:
qrc:/main.qml:31不创建布局类型的对象
当我尝试使用Layout.minimumWidth:200
或Layout{minimumWidth:200}
Qt显示了第一个正在工作的窗体。我错过了什么
导入QtQuick 2.7
导入QtQuick.Controls 2.0
导入QtQuick.Layouts 1.3
应用程序窗口{
id:窗口
标题:“RB3Jay”
宽度:1280;高度:960
最小宽度:600;最小高度:300
可见:正确
长方形{
id:伪内容
高度:parent.height-(header.height+footer.height)
颜色:'橙色'
锚定{
顶部:页眉。底部
底部:footer.top
左:parent.left
右:家长。对
}
}
标题:行布局{
id:标题
间距:0
身高:100
宽度:parent.width
长方形{
颜色:'红色'
布局{
最小宽度:200;最大宽度:200;首选宽度:200
填充高度:正确
}
}
长方形{
颜色:'绿色'
布局{
最小宽度:200
首选宽度:父级。宽度*0.7
fillWidth:真;fillHeight:真
}
}
长方形{
颜色:'蓝色'
布局{
最小宽度:200
preferredWidth:parent.width*0.3
fillWidth:真;fillHeight:真
}
}
}
页脚:检查员{
id:页脚
身高:100
}
}
虽然foo{bar:1;baz:2}
-语法适用于,但foo{}
保留用于创建QML类型的实例foo
。对于,必须使用Foo.bar:1
-语法
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
id: window
title: "RB3Jay"
width:1280; height:960
minimumWidth:600; minimumHeight:300
visible: true
Rectangle {
id: pseudocontent
height: parent.height - (header.height + footer.height)
color:'orange'
anchors {
top:header.bottom
bottom:footer.top
left:parent.left
right:parent.right
}
}
header: RowLayout {
id: header
spacing: 0
height: 100
width: parent.width
Rectangle {
color:'red'
Layout.minimumWidth:200
Layout.maximumWidth:200
Layout.preferredWidth:200
Layout.fillHeight:true
}
Rectangle {
color:'green'
Layout.minimumWidth: 200
Layout.preferredWidth: parent.width*0.7
Layout.fillWidth:true; Layout.fillHeight:true
}
Rectangle {
color:'blue'
Layout.minimumWidth: 200
Layout.preferredWidth: parent.width*0.3
Layout.fillWidth:true; Layout.fillHeight:true
}
}
footer: Inspector {
id: footer
height:100
}
}
不是可创建的类型,它仅提供附加属性。因此,必须使用Foo.bar:1
-语法
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
id: window
title: "RB3Jay"
width:1280; height:960
minimumWidth:600; minimumHeight:300
visible: true
Rectangle {
id: pseudocontent
height: parent.height - (header.height + footer.height)
color:'orange'
anchors {
top:header.bottom
bottom:footer.top
left:parent.left
right:parent.right
}
}
header: RowLayout {
id: header
spacing: 0
height: 100
width: parent.width
Rectangle {
color:'red'
Layout.minimumWidth:200
Layout.maximumWidth:200
Layout.preferredWidth:200
Layout.fillHeight:true
}
Rectangle {
color:'green'
Layout.minimumWidth: 200
Layout.preferredWidth: parent.width*0.7
Layout.fillWidth:true; Layout.fillHeight:true
}
Rectangle {
color:'blue'
Layout.minimumWidth: 200
Layout.preferredWidth: parent.width*0.3
Layout.fillWidth:true; Layout.fillHeight:true
}
}
footer: Inspector {
id: footer
height:100
}
}
哇!我确信Layout.minimumWidth会抛出相同的错误,但我一定是弄错了。我的问题无效。谢谢你的帮助。