为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

海绵宝宝撒 2021-09-02 17:25:11
我正在构建一个 Python + QtQuick 应用程序,它需要一个从QQuickPaintedItem 降级的类。我在管理已绘制项目的布局和大小时遇到了一些麻烦。特别是,我有一个看起来像这样的应用程序左侧有一组按钮,窗口右侧是一个加载程序(这是一个很好的理由,这只是演示问题的最小示例)。主 qml 文件 ( main.qml) 如下所示:import QtQuick 2.7import QtQuick.Controls 2.1import QtQuick.Layouts 1.3ApplicationWindow {    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.7import QtQuick.Controls 2.1import QtQuick.Layouts 1.3import CustomPaintedItem 1.0ColumnLayout {    anchors.fill: parent    Label {        text: "Here's a thing!"    }    CustomPaintedItem {        Layout.fillHeight: true        Layout.fillWidth: true    }}
查看完整描述

1 回答

?
噜噜哒

TA贡献1784条经验 获得超7个赞

在不使用 Loader 的情况下,布局仅处理子项:ColumnLayout自 amaximumWidth建立以来,它占用可用空间,因此它将是无限的(可以等价于 的一切Layout.fillWidth: true)。另一方面,不是 Layout 的 Loader 没有该大小策略,因此如果您希望它占用所有可用空间,则必须Layout.fillWidth: true明确使用。


Loader {

    id: contentAreaLoader

    Layout.fillHeight: true

    Layout.preferredWidth: 520

    Layout.minimumWidth: 300

    Layout.fillWidth: true // <----

    source: 'loaded_content.qml'

}


查看完整回答
反对 回复 2021-09-02
  • 1 回答
  • 0 关注
  • 236 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信