0
在Qt 5.9中的QML应用程序中,我想在Flow中显示Rectangle s,其固定宽度为s。为了保持布局居中,我尝试动态调整其填充。要计算正确的值,虽然我需要知道当前的列数,例如colCount。有没有办法得到它?QML流中的列数
这里是我想使用伪变量colCount做一个代码示例:
import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 800
height: 600
title: qsTr("Example")
Flow {
anchors.fill: parent
leftPadding: parent.width > 200*colCount ? 0.5*(parent.width - 200*colCount) : 0
spacing: 0
Rectangle {
width: 200
height: 200
color: "red"
}
Rectangle {
width: 200
height: 200
color: "blue"
}
}
}