Skip to content

Example Image cloning

Stephen Quan edited this page Nov 22, 2022 · 4 revisions
import QtQuick
import QtQuick.Controls
import qmlonline
Page {
    Rectangle {
        id: rect
        x: 50
        y: 50
        width: 50
        height: 50
        color: "red"
        Rectangle {
            anchors.centerIn: parent
            width: 30
            height: 30
            color: "orange"
        }
    }
    Image {
        id: img
        x: 250
        y: 50
    }
    Frame {
        x: 50
        y: 300
        width: parent.width - 100
        TextEdit {
            id: txt
            width: parent.width
            wrapMode: Text.WrapAtWordBoundaryOrAnywhere
        }
    }
    Component.onCompleted: {
        rect.grabToImage(function (result) {
            let buf = System.image(result.image);
            img.source = txt.text = buf.toDataURL();
        } );
    }
}

You can Try it Online!