1. 程式人生 > 其它 >《QDebug 2020年12月》

《QDebug 2020年12月》

技術標籤:QDebug 稍縱即逝的追尋

一、Qt Widgets 問題交流

1.

二、Qt Quick 問題交流

1.佈局巢狀時出現迴圈繫結提示

多個佈局巢狀使用時,如果綁定了 parent 佈局的寬高為 item 的 preferred 寬高,就會出現迴圈繫結的提示。可以把尺寸繫結到外層的元件消除該提示。

錯誤示例:

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.12

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("龔建波 1992")

    ColumnLayout{
        anchors.fill: parent
        Component.onCompleted: console.log("col")
        RowLayout{
            id: row
            Layout.fillHeight: true
            Layout.fillWidth: true
            Component.onCompleted: console.log("row")

            //巢狀使用佈局時,繫結佈局會出現迴圈繫結的提示
            //此時需要有元素fillWidth才能正常顯示
            Rectangle{
                Layout.fillHeight: true
                Layout.fillWidth: true
                Layout.preferredWidth: row.width*0.4
                color: "green"
                Component.onCompleted: console.log("green")
            }
            Rectangle{
                Layout.fillHeight: true
                Layout.fillWidth: true
                Layout.preferredWidth: parent.width*0.6
                color: "red"
                Component.onCompleted: console.log("red")
            }
        }

        //未巢狀佈局時,無提示
        Rectangle{
            Layout.fillWidth: true
            Layout.preferredHeight: parent.height*0.5
            color: "orange"
            Component.onCompleted: console.log("orange")
        }
    }
}

三、其他

1.