例如,这有效:
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.2
ApplicationWindow
{
visible: true
width: 640
height: 480
title: qsTr("Hello World")
function thingWidth()
{
return width*80/100
}
Column
{
spacing: 10;
anchors.horizontalCenter: parent.horizontalCenter
Thing { color: "red"; width: thingWidth(); }
Thing { color: "yellow"; width: thingWidth(); }
Thing { color: "green"; width: thingWidth(); }
}
}
Run Code Online (Sandbox Code Playgroud)
但Column改为ColumnLayout,它没有(调整窗口大小会导致布局出错).
任何帮助,谢谢.
编辑1:
这也是Thing.qml按要求,
import QtQuick 2.0
Item {
property alias color: rectangle.color
width: 50; height: 50
Rectangle
{
id: rectangle
border.color: "white"
anchors.fill: parent
}
}
Run Code Online (Sandbox Code Playgroud)
看起来我的帖子主要是代码.是的,保姆呢!那是因为人们在这里发布代码.
从文档的Column:
Column是一种将子项目沿一列定位的类型.它可以用作垂直定位一系列项目而不使用锚点的便捷方式.
而且,它简化了插入,删除等过程中的转换.它还将属性附加到项目上,以便为其提供有关其位置的概念.
另一方面,这是文档GridLayout(请注意,这ColumnLayout是一个方便实用程序,但它只不过是一个列有一列的网格,从其文档中).
它具有完全不同的属性集以及附加属性,完全取决于项目的排列.
我想无论如何,文档中最有趣的页面就是那个.
我只是引用它:
定位器项是管理声明性用户界面中项的位置的容器项.定位器的行为方式与标准Qt小部件使用的布局管理器类似,只是它们本身也是容器.
当需要以常规布局排列时,定位器可以更轻松地处理许多项目.
Qt Quick Layouts也可用于在用户界面中安排Qt Quick项目.它们在声明性用户界面上管理项目的位置和大小,非常适合可调整大小的用户界面.
请注意,a Column是a Positioner,而a ColumnLayout是a Layout.何时使用它们主要取决于你的目标,像往常一样.
| 归档时间: |
|
| 查看次数: |
6864 次 |
| 最近记录: |