Congratulations to our 2022 Qt Champions!

RubberBand in qml

  • I want to crop the Image in qml, like this


    The region surrounded by the rectangle is the region I want to crop
    Do Qt provide any tools to make this job easier?

    import QtQuick 2.1
    import QtQuick.Controls 1.0
    //import QtQuick.Layouts 1.0
    //import QtQuick.Dialogs 1.0

    Rectangle {
    id: root
    width: 1200
    height: 600

        anchors.fill: parent
        color: "black"
            id: rectDrag
            height: 100
            width: 100
            color: "transparent"
            border.width: 5
            border.color: "green"
            radius: 10
            MouseArea {
                id: dragArea
                anchors.fill: parent


    I can drag the rectangle and find out the coordinates of the rectangle
    But there are two questions I don't know how to solve

    1 : How could I adjust the size of rectDrag by pulling the corners of the rectDrag?
    2 : After I select the region, I need to translate the coordinates(region) to the coordinates
    of the original image, how could I translate the coordinates after scaling by the

    edit: found Qt offer a rubberband class in c++, maybe I could use it to implement the

Log in to reply