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"
}
}
}