我正在制作一個以發短信為特色的應用程式。我希望短信能像普通的短信應用一樣,從底部到頂部添加到列的布局中。如果只有幾條資訊或一條資訊,它們將出現在視圖的底部而不是頂部。現在,資訊是由上至下添加的,我不知道如何讓它以我想要的方式出現。目前我的代碼是這樣的:
而這里是我的代碼:
Rectangle {
id: conversationView
SplitView.fillWidth: false
SplitView.minimumWidth:400
color: "#ffffff"
anchors.left: sideBar.right
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.leftMargin: 0
anchors.rightMargin: 0 anchors.rightMargin: 0
anchors.topMargin: 0 anchors.topMargin: 0
anchors.bottomMargin: 0 0
矩形 {
id: conversationTopBar
y: 0
高度。45
color: "#cbcbcb".
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: 0
anchors.rightMargin: 0
標簽 {
id: contactLabel
y: 14
寬度: 250
顏色: "#000000"/span>
文本。qsTr("Contact Name")
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
font.pointSize: 13。
anchors.leftMargin: 20 20
font.bold: true true
}
IconBtn {
x: 452
y: 3
高度: contactLabel.高度 * 1.25
寬度:高度
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
iconBig:20。
doAnimation: false[/span]。
iconColor: "#000000"。
btnIconSource。".../images/icons/three_dots_vertical.svg"
anchors.rightMargin: 10
}
}
DropShadow {
anchors.fill: conversationTopBar
半徑。10.0
樣本。17
顏色: "#aa000000"/span>
來源: conversationTopBar
z: 3
}
分割視圖 {
id: conversationSplitView
anchors.left: parent.left
anchors.right: parent.right
anchors.top: conversationTopBar.bottom
anchors.bottom: parent.bottom
anchors.leftMargin: 5。
方向。Qt.Vertical
anchors.topMargin: 0
處理。矩形 {
implicitHeight: 8
color: "#050633"/span>
影像 {
id: horizontalDots
anchors.centerIn: parent.Center
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
源。".../images/icons/three_dots_horizontal.svg"。
填充方式。Image.PreserveAspectFit
anchors.top: parent.top
anchors.bottom: parent.bottom
}
顏色疊加 {
錨點.填充:horizontalDots
來源: horizontalDots
顏色:"white"。
抗鋸齒。true true
}
}
矩形 {
id: messagesView
color: "#ffffff"/span>
SplitView.fillHeight: true
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.topMargin: 0
anchors.leftMargin: 0 anchors.leftMargin: 00
ScrollView {
id: messagesScroll
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
contentWidth:寬度
anchors.topMargin: 0
anchors.bottomMargin: 0 0
anchors.leftMargin: 0
anchors.rightMargin: 0
ColumnLayout {
id: columnLayout
高度。100
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.rightMargin: 20
anchors.leftMargin: 20 anchors.leftMargin: >2020 anchors.topMargin: 20
間距。20 20
TextMessage {
messageText: "Hello World!
}
文本資訊 {
text: "和所有居住在這里的人!"
Layout.align。Qt.AlignRight | Qt.AlignVCenter
messageText: "Hello World!"
}
}
}
}
矩形 {
id: compositionView
SplitView.minimumHeight: 55。
SplitView.preferredHeight: 55 SplitView.preferredHeight: 55200
color: "#ffffff"
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.leftMargin: 0 anchors.leftMargin: 00 anchors.rightMargin.
訊息合成器 {
anchors.left: parent.left
anchors.right: sendMsgBtn.left
anchors.top: parent.top
anchors.bottom: parent.bottom
clearTxtBtnColor: "#0e1052"。
textColor: "#000000"。
anchors.rightMargin: 10
anchors.leftMargin: 10
anchors.bottomMargin: 10 錨點.底部邊距:10
anchors.topMargin: 10 anchors.topMargin: 10
}
IconBtn {
id: sendMsgBtn
x: 447
y: 8
anchors.right: parent.right
iconColor: "#0e1052"/span>
anchors.rightMargin: 10
btnIconSource: ".../images/icons/send.svg" btnIconSource.
}
}
}
}
uj5u.com熱心網友回復:
你通常會使用一個視圖來處理這樣的事情。ListView的相關屬性是verticalLayoutDirection:
verticalLayoutDirection: ListView.BottomToTop
在Qt中,有一個聊天的例子可以做到這一點:
https://doc.qt.io/qt-5/qtquickcontrols-chattutorial-example.html你可以為任何ListView添加一個ScrollBar,或者將ListView包裹在一個ScrollView中
。轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/310164.html
標籤:
