There is a qml window, it is necessary to position the picture in the center and add the ability to move this picture with the mouse (ideally, I would like to move only the picture that does not fit in the window, but forbid a small one to move). To add the ability to move using the Flickable block. The following problem arises: a picture that is larger than the window is positioned correctly in the center of the window, and the small picture is shifted to the origin. Tell me what I'm doing wrong.

PS: never found an example of how to add a condition on the ability to move.

 import QtQuick 2.5 import QtQuick.Window 2.2 Window { id: win visible: true width: 1000; height: 1000 Flickable { clip : true width: 1000; height: 1000 anchors.fill: parent contentHeight: myIcon.height contentWidth: myIcon.width //contentX: myIcon.width < width ? width / 2 - myIcon.width / 2 :myIcon.width / 2 - width / 2 //contentY: myIcon.height < height ? height / 2 - myIcon.height / 2 :myIcon.height / 2 - height / 2 contentX: myIcon.width / 2 - width / 2 contentY: myIcon.height / 2 - height / 2 Image { id: myIcon anchors.centerIn: parent source: "1.jpg" } } } 

    1 answer 1

    Apparently

     anchors.centerIn: parent 

    does not work if the parent is Flickable or does not work as it would be desirable for the reason that it is necessary to center the picture not in Flickable , but in its content. The first thing that comes to mind is to make an intermediate Item that will be content for Flickable . Like that:

      Flickable { anchors.fill: parent contentHeight: idContent.height contentWidth: idContent.width Item { id: idContent width: math.max(1000, myIcon.width) height: math.max(1000, myIcon.height) Image { id: myIcon anchors.centerIn: parent source: "1.jpg" } } } 

    Or you can use the leftMargin and rightMargin to center a small image.

    The Flicable property includes the ability to move - interactive.