用鼠标滚动文本 单击并按住,就像触摸屏一样

Scroll a text by mouse Click and hold like a touch screen

我需要通过鼠标单击来滚动,当单击滚动条或在滚轮上时,下面的代码工作得很好,但我需要通过鼠标单击并按住文本中的任意位置。

ScrollView {
    id: scrollView
    x: 15
    y: 38
    width: 647
    height: 168
    visible: true
    spacing: 2
    focusPolicy: Qt.ClickFocus
    clip: true
    
    Text {
        id: text1
        x: -17
        y: -27
        opacity: 1
        visible: true
        color: "#ffffff"
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        font.pixelSize: 16
        verticalAlignment: Text.AlignVCenter
        wrapMode: Text.WrapAnywhere
        font.preferShaping: false
        font.kerning: false
        font.styleName: "Bold"
        style: Text.Normal
        font.weight: Font.Medium
        font.bold: true

        clip: true
        anchors.topMargin: 0
        anchors.bottomMargin: -8
        anchors.leftMargin: 0
        anchors.rightMargin: 0
        font.family: "Courier New"

    }
}

您可以使用 Flickable 而不是 ScrollView。

一个真正基本的示例应该是这样的。

Flickable {
  width: 200; height: 100
  contentWidth: text.width; contentHeight: text.height
  
  // These create default scroll bars for both orientations.
  // You could modify the scroll bars if you want.
  ScrollBar.vertical: ScrollBar{}
  ScrollBar.horizontal: ScrollBar{}

  Text{ id: text; width: 200; height: 300; text: "Some long text here" }
}