user16451365
user16451365

Reputation:

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

I need to scroll by mouse click ,the code bellow works very well when scroll bars clicked or on wheel,BUT I need by mouse click and hold in anywhere in text.

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"

    }
}

Upvotes: 0

Views: 397

Answers (1)

U.Tuken
U.Tuken

Reputation: 228

You can use a Flickable instead of ScrollView.

A really basic sample would be like this.

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" }
}

Upvotes: 2

Related Questions