You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyQt6中使用QML SplitView实现三个横向可调整大小的元素时,前两个区域宽度被挤压为0的问题求助

PyQt6中使用QML SplitView实现三个横向可调整大小的元素时,前两个区域宽度被挤压为0的问题求助

大家好,我最近在用PyQt6开发桌面应用,想做一个能通过横向拖动调整三个逻辑区域大小的UI,本来觉得SplitView就是最适合的组件,结果实际用起来却踩坑了。

我在Qt5的官方文档里找到了一个完全匹配我需求的示例,它实现的就是三个横向可调整的面板,于是我直接把代码拿过来想适配到Qt6环境下使用,代码如下:

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts

ApplicationWindow {
    height: 600
    visible: true
    width: 1200

    SplitView {
        anchors.fill: parent
        orientation: Qt.Horizontal

        Rectangle {
            Layout.maximumWidth: 400
            color: "lightblue"
            width: 200
            Text {
                anchors.centerIn: parent
                text: "View 1"
            }
        }

        Rectangle {
            id: centerItem
            Layout.fillWidth: true
            Layout.minimumWidth: 50
            color: "lightgray"
            Text {
                anchors.centerIn: parent
                text: "View 2"
            }
        }

        Rectangle {
            color: "lightgreen"
            width: 200
            Text {
                anchors.centerIn: parent
                text: "View 3"
            }
        }
    }
}

但运行后结果完全不符合预期,前两个区域的宽度直接被挤压成0了,根本看不到正常的三个可调整面板。有没有大佬遇到过类似的问题?或者能帮我看看代码哪里出问题了吗?求指点!

备注:内容来源于stack exchange,提问作者Silk0vsky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 09:33:12