本文主要是介绍Qt/QML学习-ScrollView,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
QML学习
- ScrollView例程
- 视频讲解
- 代码
main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15Window {width: 640height: 480visible: truetitle: qsTr("Hello World")ScrollView {id: scrollViewwidth: 200height: 200anchors.centerIn: parentclip: trueScrollBar.vertical.policy: ScrollBar.AlwaysOnScrollBar.horizontal.policy: ScrollBar.AlwaysOnbackground: Rectangle {color: "yellow"}TextEdit {id: textEditanchors.centerIn: parenttext: "ScrollView + TextEdit"color: "red"font{pointSize: 30bold: true}selectByMouse: trueselectionColor: "blue"cursorDelegate: Canvas {width: 4onPaint: {var ctx = getContext('2d')ctx.setLineDash([2, 2, 2])ctx.lineWidth = 4ctx.strokeStyle = "#444fff"ctx.lineCap = "round"ctx.beginPath()ctx.moveTo(0, 0)ctx.lineTo(0, height)ctx.stroke();}}}}function scrollViewAddText(text) {// 给TextEdit添加文本textEdit.text += text// 调整视图到scrollView底部scrollView.ScrollBar.vertical.position =scrollView.contentHeight>scrollView.height?(scrollView.contentHeight - scrollView.height)/ scrollView.contentHeight: 0}Button {anchors.left: scrollView.rightanchors.top: scrollView.toptext: "添加文本"onClicked: {scrollViewAddText("\n一键三连")}}
}
演示
视频讲解
这篇关于Qt/QML学习-ScrollView的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!