为什么我的按钮在 QML ColumnLayout 中重叠?

问题描述 投票:0回答:1

似乎有一些关于 QML 布局的基本知识我不明白。

我有以下 QML。

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

ApplicationWindow {
    id: applicationWindow

    visible: true
    title: "API control panel"

    Connections {
        target: __ApiObj
    }
    Connections {
        target: __VideotestObj
    }
    Connections {
        target: __ButtonListObj
    }

    ColumnLayout {
        Button {
            id: apiEnabler
            text: "Button 0"
            onClicked: __ApiObj.set_enable_api(!__ApiObj.is_running_prop)
        }
        Button {
            id: videotestPipeline
            text: "Button 1"
            onClicked: __VideotestObj.set_enable_pipeline(!__VideotestObj.is_running_prop)
        }
        Button {
            id: playgroundPipeline
            text: "Button 2"
            onClicked: __PlaygroundObj.set_enable_pipeline(!__PlaygroundObj.is_running_prop)
        }
        ListView {
            id: buttonList
            anchors.fill: parent // Uncomment to show
            clip: true
            model: __ButtonListObj.model
            delegate: Button {
                text: "ListView Button"
                onClicked: model.modelData.set_enable_pipeline(!model.modelData.is_running_prop)
            }
        }
    }
}

3 个

Button
按钮 0按钮 1按钮 2 按预期显示。默认情况下,根本不显示
ListView
,除非我取消注释
anchors.fill: parent
。问题在于它是未定义的行为(正如日志消息告诉我的那样)并且很丑陋,因为委托被绘制在其他按钮之上。

是什么阻止

ColumnLayout
按钮2
下方绘制我的ListView

qt layout qml
1个回答
0
投票

使用

Layout.fillWidth: true
Layout.fillHeight: true
代替
anchors.fill: parent
。在布局中,大小调整不受锚点控制

© www.soinside.com 2019 - 2024. All rights reserved.