Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

ScrollView Binding Loop



  • I am trying to create a zoom control using the ScrollView. Under normal conditions I want the content of the ScrollView to be the same size as the container. Then when you zoom in, I want the contents to be the size * 2. This will give you a bigger size content that you can scroll to see.

    Item
    {
    id: container
    anchors.fill: parent

    ScrollView
    {
        anchors.fill: parent
    
        Rectangle
        {
            height: surfaceContainer.height
            width: surfaceContainer.width
        }
    }
    

    }

    The problem is this causes a binding loop.
    qrc:/Qml/CustomScrollView.qml:322:9: QML ScrollViewHelper: Binding loop detected for property "horizontalScrollbarOffset"
    file:///C:/Qt/5.5/msvc2013/qml/QtQuick/Controls/Private/ScrollViewHelper.qml:124:5: QML ScrollBar: Binding loop detected for property "height"

    I tracked it down to this code in the ScrollViewer

    property int horizontalScrollbarOffset: horizontalScrollBar.visible && !horizontalScrollBar.isTransient ?
    horizontalScrollBar.height + scrollBarSpacing : 0

    It seems like it uses the scroll bar height to figure out the offset which causes the loop. If I take this out it works fine, but then it resets the scroll position every time.

    Is there any good way to get around this? Is there another control I could use instead of doing it this way.


  • Moderators

    @krobinson Try updating those properties by assignment i.e using = when height or width change signal handler.


Log in to reply