【发布时间】:2018-06-14 10:02:15
【问题描述】:
我正在为我的示例寻找解决方案。我想拖动矩形的一个角,它会改变比例,但是当我拖动一个角来缩小矩形时,它会出错。
请给出一个解决方案。非常感谢!
================================================ ==================================================== ==================================================== ===
我的代码:
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
title: qsTr("Test Crop")
width: 640
height: 480
visible: true
property double photohfake: selComp.height
property double photowfake: selComp.width
property double photowold: selComp.width
property double photohold: selComp.height
Image {
id: image1
anchors.fill: parent
source: "http://dongdomobile.vn/wp-content/uploads/2014/09/Cute-Grey-Seamless-Pattern-For-Website-Background-300x136.jpg"
Rectangle {
x:parent.width / 4
y: parent.height / 4
width: parent.width / 2
height: parent.width / 2
id: selComp
border {
width: 2
color: "steelblue"
}
color: "#354682B4"
Rectangle {
width: 18
height: 18
color: "steelblue"
anchors.verticalCenter:parent.top
anchors.horizontalCenter: parent.left
MouseArea {
anchors.fill: parent
drag{ target: parent; axis: Drag.XAndYAxis }
onPositionChanged: {
console.log("mouseX "+mouseX)
console.log("mouseY "+mouseY)
if(drag.active){
photohfake=photohfake-mouseY //calculator new height
selComp.scale=selComp.scale/photohold*photohfake //calculator new scale
photowfake=photowold*photohfake/photohold //calculator new width
selComp.x+=(photowold-photowfake)/2
selComp.y+=mouseY/2
console.log("photohfake "+photohfake)
console.log("photohold "+photohold)
photohold=photohfake
photowold=photowfake
console.log("selComp.scale "+selComp.scale)
if(selComp.scale<0.5)
selComp.scale=0.5
else if(selComp.scale>4)
selComp.scale=4
}
}
}
}
}
}
}
【问题讨论】:
-
你遇到了什么错误?
-
矩形的形状发生了奇怪的变化!