1

I want to be able to print the height/width of the Flickable view while dragging it. I believe it can be done using onDraggingChanged or onMovingChanged, since a similar event listener onTextChanged does the job of listening text changes in text controls. I tried this:

    Flickable{
    id: flick
    height: parent.height - 40
    width: parent.width - 40
    anchors.bottom: parent.bottom
    anchors.right: parent.right
    anchors.margins: 20
    flickableDirection: Flickable.HorizontalAndVerticalFlick
    Rectangle{
        anchors.fill: parent
        color: "steelblue"
    }
    onMovingChanged: {
        console.log("onMovingChanged")
        console.log("height:", height)
    }
    onDraggingChanged: {
        console.log("onDraggingChanged")
        console.log("height:", height)
    }
}

But those event listeners will only print the height on the start and end of dragging/moving the flickable. So how do I achieve this?

jpnurmi
  • 5,716
  • 2
  • 21
  • 37
Akash Agarwal
  • 2,326
  • 1
  • 27
  • 57
  • You know that the height will never change in your example, right? Besides, printing something in the onContentXChanged/onContentYChanged as Filip suggests will likely slow your GUI down. – Yoann Quenach de Quivillic Jun 13 '16 at 13:30
  • @Yoann I wanted to play around with animations and resizing of layouts so I needed to know the height at each location. I'm very much aware about the drawback of using it :) – Akash Agarwal Jun 13 '16 at 19:20

1 Answers1

2

I believe Flickable.contentXChanged and Flickable.contentYChanged signals are what you need.

  • Flickable.draggingChanged is emitted only when drag is starting and ending.
  • Flickable.movingChanged is emitted only when Flickable starts and ends moving.
  • Flickable.contentXChanged is emitted every time content is being moved horizontally.
  • Flickable.contentYChanged is emitted every time content is being moved vertically.

Also Text.textChanged is emitted every time text changes.

Filip Hazubski
  • 1,668
  • 1
  • 17
  • 33
  • Sorry for the delay, I looked into this link: http://doc.qt.io/qt-5/qml-qtquick-flickable.html#flickEnded-signal and I can't find those 4 signals. Can you please link me to a doc? – Akash Agarwal Jun 13 '16 at 18:07
  • 2
    @AkashAggarwal You do not see them in the docs because in QML every property has `changed` signal. Even when you create your own properties. You can read about it [here](http://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html). That is how QML works and this is why you can bind values so easily. Everytime property changes value the signal is emitted and all values that are based on this value are being recalculated. So there is no `Flickable.contentXChanged` in the docs but there is `Flickable.contentX`. – Filip Hazubski Jun 13 '16 at 19:07
  • Thanks, this info was helpful in knowing QML better. – Akash Agarwal Jun 13 '16 at 19:18