首页 > 解决方案 > 为什么锚点更改后项目会消失?

问题描述

这是我的 qml 文件中 TabView 中的一个选项卡:

    Tab {
            title: "Lab"
            Rectangle {
                width: 300
                height: 600
                anchors.margins: 60
                color: "gray"
//                anchors.top: parent.top
//                anchors.bottom: parent.verticalCenter
//                anchors.margins: 10
                Column {
                    id : buttons
//                                    anchors.top: parent.top
//                                    anchors.bottom: parent.verticalCenter
                    anchors.fill: parent
                                    anchors.margins: 10
                    spacing: 2

                    Repeater {
                        model: ["Add entity", "Add Unique Comp", "Add light", "Add Prefab", "Add entity to prefab", "None"]

                        Rectangle {
                            width: parent.width - 20
                            height: 24
                            anchors.horizontalCenter: parent.horizontalCenter

                            radius: 3

                            color: "lightBlue"

                            Button {
                                width: parent.width * 0.5
                                height: parent.height * 0.8
                                anchors.left: parent.left
                                anchors.verticalCenter: parent.verticalCenter
                                text: index +": "+modelData
                                onClicked: {
                                    console.log("clicked ", modelData);
                                }
                            }
                        }
                    }
                }
            }
        }

这里使用了一个 TabView,上面是其中一个选项卡。x y未指定。

如果我删除anchors.fill: parentRectangle将在屏幕上消失。为什么会这样?或者我怎么能调试这个?

标签: qtqml

解决方案


推荐阅读