QtQuick GeometryChanged 方法仅适用于加载组件的一个方向

我正在构建一个 Python + QtQuick 应用程序,它需要一个从QQuickPaintedItem 降级的类。我在管理已绘制项目的布局和大小时遇到了一些麻烦。

特别是,我有一个看起来像这样的应用程序

http://img.mukewang.com/6130b2400001255307170511.jpg

左侧有一组按钮,窗口右侧是一个加载程序(这是一个很好的理由,这只是演示问题的最小示例)。


主 qml 文件 ( main.qml) 如下所示:


import QtQuick 2.7

import QtQuick.Controls 2.1

import QtQuick.Layouts 1.3


ApplicationWindow {

    id: mainWindow

    visible: true

    width: 720

    height: 480

    title: qsTr("QML Sampler")

    onClosing: main.close_application()


    RowLayout {

        anchors.fill: parent


        ColumnLayout {

            id: sideBar

            Layout.fillHeight: true

            Layout.preferredWidth: 200

            Layout.minimumWidth: 150

            Layout.maximumWidth: 350


            Button {

                id: buttonScreen1

                text: "Button 1"

                Layout.fillWidth: true

            }


            Button {

                id: buttonScreen2

                text: "Button 2"

                Layout.fillWidth: true

            }

        }


        Loader {

            id: contentAreaLoader

            Layout.fillHeight: true

            Layout.preferredWidth: 520

            Layout.minimumWidth: 300


            source: 'loaded_content.qml'

        }

    }

}

加载的内容文件是实际包含自定义类的文件,如下所示 ( loaded_content.qml):


import QtQuick 2.7

import QtQuick.Controls 2.1

import QtQuick.Layouts 1.3


import CustomPaintedItem 1.0


ColumnLayout {

    anchors.fill: parent


    Label {

        text: "Here's a thing!"

    }


    CustomPaintedItem {

        Layout.fillHeight: true

        Layout.fillWidth: true

    }

}


海绵宝宝撒
浏览 278回答 1
1回答

噜噜哒

在不使用 Loader 的情况下,布局仅处理子项:ColumnLayout自 amaximumWidth建立以来,它占用可用空间,因此它将是无限的(可以等价于 的一切Layout.fillWidth: true)。另一方面,不是 Layout 的 Loader 没有该大小策略,因此如果您希望它占用所有可用空间,则必须Layout.fillWidth: true明确使用。Loader {&nbsp; &nbsp; id: contentAreaLoader&nbsp; &nbsp; Layout.fillHeight: true&nbsp; &nbsp; Layout.preferredWidth: 520&nbsp; &nbsp; Layout.minimumWidth: 300&nbsp; &nbsp; Layout.fillWidth: true // <----&nbsp; &nbsp; source: 'loaded_content.qml'}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python