【发布时间】:2020-10-20 14:21:27
【问题描述】:
我一直在尝试使用 Qt Quick Controls 2 创建一个以编程方式滚动到 ScrollView 底部的函数。 我尝试了各种选项,但我在网上找到的大部分支持都是指 Qt Quick Controls 1,而不是 2。这是我尝试过的:
import QtQuick 2.8
import QtQuick.Controls 2.4
ScrollView {
id: chatView
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: inputTextAreaContainer.top
function scrollToBottom() {
// Try #1
// chatView.contentItem.contentY = chatBox.height - chatView.contentItem.height
// console.log(chatView.contentItem.contentY)
// Try #2
// flickableItem.contentY = flickableItem.contentHeight / 2 - height / 2
// flickableItem.contentX = flickableItem.contentWidth / 2 - width / 2
// Try #3
chatView.ScrollBar.position = 0.0 // Tried also with 1.0
}
TextArea {
id: chatBox
anchors.fill: parent
textFormat: TextArea.RichText
onTextChanged: {
// Here I need to scroll
chatView.scrollToBottom()
}
}
}
有谁知道如何使用 Qt Quick Controls 2 来实现这一点? 如果没有,是否有人可以替代这种方法?
【问题讨论】:
标签: qt qml qtquick2 qtquickcontrols2