QML中能否实现A与C、B与D垂直拆分?代码问题求助
QML实现A-C、B-D垂直拆分的可行方案
你的需求完全可以实现,问题出在嵌套结构逻辑错误。当前代码是把两个带水平拆分的RowLayout塞进垂直SplitView,导致整体上下拆分,而非A与C、B与D各自垂直拆分。
修正后的代码
ColumnLayout { anchors.fill: parent spacing: 20 // 外层水平SplitView:拆分左右两部分(A/C组 和 B/D组) SplitView { Layout.fillWidth: true Layout.fillHeight: true orientation: Qt.Horizontal // 左侧垂直SplitView:A(上)和C(下)垂直拆分 SplitView { SplitView.preferredWidth: 200 SplitView.fillHeight: true orientation: Qt.Vertical Rectangle { SplitView.fillWidth: true SplitView.preferredHeight: 250 color: "lightblue" Text { anchors.centerIn: parent; text: "View A" } } Rectangle { SplitView.fillWidth: true SplitView.fillHeight: true color: "lightblue" Text { anchors.centerIn: parent; text: "View C" } } } // 右侧垂直SplitView:B(上)和D(下)垂直拆分 SplitView { SplitView.fillWidth: true SplitView.fillHeight: true orientation: Qt.Vertical Rectangle { SplitView.fillWidth: true SplitView.preferredHeight: 250 color: "lightgreen" Text { anchors.centerIn: parent; text: "View B" } } Rectangle { SplitView.fillWidth: true SplitView.fillHeight: true color: "lightgreen" Text { anchors.centerIn: parent; text: "View D" } } } } }
关键调整点
- 外层改为水平SplitView,将界面分为左右两个区域,分别对应A/C组和B/D组
- 左右两个区域各自使用垂直SplitView,实现A与C、B与D的上下拆分
- 给每个SplitView子项设置合适的
SplitView属性,确保布局填充和尺寸优先级正确
内容的提问来源于stack exchange,提问作者Jeyanth Inba
相关产品推荐
相关产品推荐

