【发布时间】:2014-09-25 07:30:18
【问题描述】:
我在 QML (QtQuick 1.0) 中有一个图像对象,它的高度必须是相对的(在窗口缩放的情况下),但问题是当我尝试以全尺寸显示此图像时。请看我的代码的以下部分:
Image {
id: selectionDialogImage
source: "qrc:/Images/myImage.png"
property int oldHeight: sourceSize.height
sourceSize.height: testsList.height/3
scale: 1
anchors.bottom: parent.bottom
anchors.left: parent.left
visible: false
property bool imageFullsize: false
MouseArea {
anchors.fill: parent
onClicked:
{
if(parent.imageFullsize)
{
parent.parent = selectionDialogQuestionText;
parent.sourceSize.width = undefined;
parent.sourceSize.height = testsList.height/3;
parent.anchors.horizontalCenter = undefined;
parent.anchors.verticalCenter = undefined;
parent.anchors.left = selectionDialogQuestionText.left;
parent.anchors.bottom = selectionDialogQuestionText.bottom;
parent.imageFullsize = false;
}
else
{
parent.parent = mainItem;
parent.sourceSize.height = parent.oldHeight;
//parent.sourceSize.height = undefined;
parent.sourceSize.width = mainItem.width;
parent.anchors.horizontalCenter = mainItem.horizontalCenter;
parent.imageFullsize = true;
}
}
}
}
selectionDialogQuestionText 是我的图像项的默认父项。 mainItem 是最大的项目,它有整个窗口的大小。因此,当我在全屏上显示图像时,我想根据宽度设置图像大小,但在另一种状态下,我想缩放图像以设置其高度。
当我设置parent.sourceSize.width = mainItem.width; 时,图像没有缩放,但它的高度和以前一样(非常小),所以它的比例不合适。
我可以以任何方式存储源图像的旧高度吗?我需要类似 const 的东西,因为 property int oldHeight: sourceSize.heigh 是相对的。或者有没有办法恢复图像的默认大小然后设置高度/宽度?
更新#1: 我尝试使用@Mitch 描述的方法:
property int oldHeight
Component.onCompleted: {
oldHeight = sourceSize.height
}
sourceSize.height: 250
但console.log("oldHeight="+parent.oldHeight) 下面几行显示oldHeight=250,而不是原始高度。
【问题讨论】:
-
你能提供你想要做什么的插图吗?你的问题很难理解。