I created a rectangle and passed the co-ordinates to draw a rectangle. Now its like when release mouse, a rectangle will be drawn, But I need to implement like, when a press mouse, I should start drawing rectangle and when I release mouse I should end the rectangle. Any suggestions?
import QtQuick 1.1
Rectangle {
id:imageRect
width: 1920
height: 988
property int pressX
property int pressY
property int releaseX
property int releaseY
property int widthRect
property int heightRect
Image{
id:imagetoshow
source:"file:///C://Users//Jakr13//Desktop//test1.bmp"
}
MouseArea {
id:roiRectArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onPressed: {
pressX = mouse.x
pressY = mouse.y
console.log("Pressed Co-ordinates",pressX,pressY);
}
onReleased: {
releaseX = mouse.x
releaseY = mouse.y
console.log("Released Co-ordinates",releaseX,releaseY);
widthRect = releaseX - pressX
heightRect = releaseY - pressY
console.log("width, height:",widthRect,heightRect);
}
}
Rectangle {
id:rectRoi
opacity: 0.4
x: pressX
y: pressY
width: widthRect
height: heightRect
color: "#ffffff"
MouseArea {
id:roiarea
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked:{
console.log("Right Button Clicked");
}
}
}
}
import QtQuick 1.1
Rectangle {
id:imageRect
width: 1920
height: 988
property int pressX
property int pressY
property int releaseX
property int releaseY
property int widthRect
property int heightRect
Image{
id:imagetoshow
source:"file:///C://Users//Jakr13//Desktop//test1.bmp"
}
MouseArea {
id:roiRectArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onPressed: {
pressX = mouse.x
pressY = mouse.y
console.log("Pressed Co-ordinates",pressX,pressY);
}
onReleased: {
releaseX = mouse.x
releaseY = mouse.y
console.log("Released Co-ordinates",releaseX,releaseY);
widthRect = releaseX - pressX
heightRect = releaseY - pressY
console.log("width, height:",widthRect,heightRect);
}
}
Rectangle {
id:rectRoi
opacity: 0.4
x: pressX
y: pressY
width: widthRect
height: heightRect
color: "#ffffff"
MouseArea {
id:roiarea
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked:{
console.log("Right Button Clicked");
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks