我是QML的新手,我正試圖實作一個有兩個孩子的水平分割視圖。我遇到的問題是,盡管為孩子們設定了最大和最小的寬度,但最后一個孩子總是占據了整個分割視圖,其他的孩子都被隱藏起來,必須手動打開。我試著用Layout.maximum/minimumwidth來定義最小和最大寬度(根本不起作用),并試著在分割視圖的第一個孩子身上使用fillwidth。似乎什么都不起作用。我甚至從splitview的qml doc頁面上復制并粘貼了代碼,結果也是如此。以下是我的代碼:
import QtQuick 2.0
importQtQuick.Controls 2.15
importQtQuick.Layouts 1.11
import ".../buttons"
import ".../customWidgets"。
矩形 {
id: conversationsPage
anchors.fill: parent
高度。455
寬度:800。
SplitView {
id: splitView
anchors.fill: parent
方向。Qt.Horizontal
矩形 {
id: sideBar
Layout.minimumWidth:200。
Layout.preferredWidth: 300500。
Layout.fillWidth:true
color: "#b9b9b9"/span>
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.topMargin: 0 anchors.topMargin: 0
夾子。true
矩形 {
id: sideBarTopBar
y: 0 矩形 { id: sideBarTopBar.
z: 2
高度。44
color: "#e868ff"/span>
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: 0
anchors.rightMargin: 0
搜索欄 {
id: conversationSearchBar
anchors.left: parent.left
anchors.right: newConversationBtn.left
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.bottomMargin: 10。
anchors.topMargin: 10 anchors.topMargin: 10
anchors.leftMargin: 10 錨點.左邊距:10
anchors.rightMargin: 10 anchors.rightMargin: 10
}
IconBtn {
id: newConversationBtn
寬度: 35
高度。35
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 10
btnIconSource。".../images/icons/plus.svg"。
}
}
ScrollView {
id: conversationsListScroll
anchors.left: parent.left
anchors.right: parent.right
anchors.top: sideBarTopBar.bottom
anchors.bottom: parent.bottom
z: 1。
anchors.topMargin: 0
ColumnLayout {
id: conversationListLayout
x: 0
y: 0
width: conversationsListScroll.width
clip: true
ConversationTab {
Layout.fillWidth: true
}
ConversationTab {
Layout.fillWidth: true
}
ConversationTab {
Layout.fillWidth: true
}
ConversationTab {
Layout.fillWidth: true
}
ConversationTab {
Layout.fillWidth: true
}
ConversationTab {
Layout.fillWidth: true
}
ConversationTab {
Layout.fillWidth: true
}
}
}
}
矩形 {
id: conversationView
Layout.fillWidth: false
Layout.minimumWidth:300。
Layout.maximumWidth:500
color: "#ff0000"/span>
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.topMargin: 0
anchors.bottomMargin: 0 anchors.bottomMargin: >0
你們知道為什么分割視圖不能按照我想要的方式作業嗎?
uj5u.com熱心網友回復:
我注意到幾件事,首先,在Quick Controls 2的SplitView中,你必須使用SplitView附件屬性而不是Layout附件屬性。
其次,我還注意到你在SplitView的直接子節點內指定了anchors,這沒有任何效果,可以被洗掉。我不確定,但似乎帶有SplitView.fillWidth: true的子代不應該設定最大寬度,因為兩個子代都有最大寬度可以阻止SplitView完全填充其父代Rectangle(你可能仍然有這樣的用例,但我因為這個原因把它洗掉了)。
以下是包含這些建議的代碼:
SplitView {
id: splitView
anchors.fill: parent
方向。Qt.Horizontal
矩形 {
id: sideBar
SplitView.minimumWidth:200。
SplitView.preferredWidth: 300
SplitView.fillWidth: true
color: "#b9b9b9"/span>
夾子。true
// children here...
}
矩形 {
id: conversationView
SplitView.fillWidth: false
SplitView.minimumWidth: 300。
SplitView.maximumWidth:500
color: "#ff0000"/span>
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/310190.html
標籤:
