Canvas resize
-
I want to "Canvas" always accept what the image dimensions will be loaded.
I also tried like you say.
@import QtQuick 2.2
import QtQuick.Controls 1.1ApplicationWindow {
visible: true
width: 640
height: 480
color: "blue"
title: qsTr("Hello World")menuBar: MenuBar { Menu { title: qsTr("File") MenuItem { text: qsTr("Exit") onTriggered: Qt.quit(); } } } Image { id: myImage source: "http://i.snag.gy/5VVZR.jpg" //onWidthChanged: myCanvas.width = width //onHeightChanged: myCanvas.height = height } Canvas { id: myCanvas anchors.bottom: parent.bottom width: myImage.width height: myImage.height onPaint: { var ctx = getContext("2d") ctx.drawImage(myImage, 0, 0) //ctx.drawImage(myImage, 0, 0, myImage.width, myImage.height) } } MouseArea { anchors.fill: parent onClicked: { myImage.source = "http://i.snag.gy/qLdPZ.jpg" //myCanvas.requestPaint() } }
}
@ -
Sorry, but i'm not actully understanding your question.
Do you want to set the width and height of Canvas to that of myImage ? -
bq. Sorry, but i’m not actully understanding your question.
Do you want to set the width and height of Canvas to that of myImage ?Yes. I want to canvas element always have the same dimensions as the image even if I load another image with different dimensions.
-
Then your 1st code works as expected. I tested with Qt5.3.1
-
I have Qt 5.3. For me it looks like this.
http://i.imgur.com/XT4j1E5.png
http://i.imgur.com/icVU9nq.pngShare your snapshots.
-
Here:
-
May be it is taking time to load the other image on your network and hence unable to determine the size.
You could try getting the "status":http://qt-project.org/doc/qt-5/qml-qtquick-image.html#status-prop of it and then assigning the dimensions. -
That's strange. Did you notice anything during reinstallation that you might have missed in first ?