Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的QML ListView与列定位器中的文本重叠?_Qml - Fatal编程技术网

为什么我的QML ListView与列定位器中的文本重叠?

为什么我的QML ListView与列定位器中的文本重叠?,qml,Qml,列定位器应该将其子项定位在列中。但当其中一个子项是ListView时,我发现它与其他子项重叠 当孩子们只是文本的时候,没有重叠,一切都很好 import QtQuick 2.11 import QtQuick.Window 2.11 Window { visible: true width: 640 height: 480 Column { Text { text: "Hello World" } //

列定位器应该将其子项定位在列中。但当其中一个子项是ListView时,我发现它与其他子项重叠

当孩子们只是文本的时候,没有重叠,一切都很好

import QtQuick 2.11
import QtQuick.Window 2.11

Window {
    visible: true
    width: 640
    height: 480

    Column {
        Text {
            text: "Hello World"
        }

// This works - appears under "Hello World"
        Text {
            text: "Hi Again"
        }

// This doesn't - overlaps "Hello World" and "Hi Again"
        ListModel {
            id: theModel
            ListElement { display: "one" }
            ListElement { display: "two" }
            ListElement { display: "three" }
        }
        ListView {
            height:100
            model: theModel
            delegate: Text {
                text: display
            }
        }
    }
}
预期结果:Listview显示在“再次Hi”下 实际结果:ListView与“Hello World”和“Hi Area”重叠

我经常在QML中出现项目重叠的情况。我是否遗漏了一些基本的东西,有人可以向我解释?我很难找到一本好的QML定位参考书。

列(以及其他定位器)将不会定位被认为不可见的项目,定义为高度
和宽度
高于零且
可见=假
。这意味着您可以通过将
列表视图
锚定到其父视图的左侧和右侧来轻松解决此问题:

    ListView {
        height:100
        anchors.left: parent.left
        anchors.right: parent.right

        Component.onCompleted: console.log(implicitHeight, implicitWidth)
        model: theModel
        delegate: Text {
            text: display
        }
    }

如果您不想看到
列表视图的滚动行为,在这里使用
中继器
而不是
列表视图
可能更适合您