[英]Qt5 QML ListView contents zoom
I am trying to implement an image viewer (sort of): 我正在尝试实现图像查看器(某种):
ListView
filled up with Image
(delegate) items Image
(代理)项的ListView
Here is a piece of code: 这是一段代码:
property double zoomFactor: 1.5;
property double imgScale: 1;
CustomToolBar
{
id: toolBar
onZoomInSignal:
{
imgScale = imgScale*zoomFactor;
}
onZoomOutSignal:
{
imgScale = imgScale/zoomFactor;
}
onZoomFitSignal:
{
imgScale = 1;
}
}
Rectangle
{
id: bgRect
Layout.fillWidth: true
Layout.fillHeight: true
color: "Grey"
anchors.margins: 10
ScrollView
{
id: scrollView
anchors.fill: parent
ListView
{
id: listView
anchors.fill: parent
clip: true
spacing: 10
model: listItemModel
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 10
boundsBehavior: Flickable.StopAtBounds
delegate: Image
{
id: item_id
anchors.horizontalCenter: parent.horizontalCenter
source: item_img_path + "/" + Math.random()
scale: imgScale
}
}
}
}
The images are loaded correctly, I need to be able to zoom them. 图像已正确加载,我需要能够缩放它们。
In order to zoom I just modify the scale
property of the Image
delegate. 为了缩放,我只修改
Image
委托的scale
属性。
scale = 1
) CORRECT: scale = 1
)正确: scale = 1/1.5
) WRONG! scale = 1/1.5
)错误! images spacing (?) is being incremented: scale = 1.5
) WRONG! scale = 1.5
)错误! images overlap: As you can see, zoom minus increments the spacing (I'm quite not sure it is really the spacing) between the images, and zoom plus overlaps the images. 如您所见, 缩放减会增加图像之间的间距(我不太确定它确实是间距),而缩放加会重叠图像。
Furthermore, it would be nice to have the horizontal scrollbar for the ScrollView
when zooming in, but I cannot achieve this. 此外,放大时在
ScrollView
放置水平滚动条会很好,但是我无法实现。
Can anyone help me? 谁能帮我?
Thanks 谢谢
EDIT: 编辑:
Following the solution proposed by grillvott the images are zoomed in/out correctly, but the whole ListView
is getting smaller/bigger with them: 按照Grillvott提出的解决方案,可以正确放大/缩小图像,但是整个
ListView
的尺寸会变得越来越小:
The result should be instead something like this (gimp mode ON): 结果应该是这样的(gimp模式为ON):
Any idea? 任何想法?
I don't think that scale
will take any boundaries into consideration. 我认为
scale
不会考虑任何界限。 You could encapsulate the image and use fillMode
to make sure the image scales accordingly: 您可以封装图像并使用
fillMode
来确保图像按比例缩放:
delegate: Item {
anchors.horizontalCenter: parent.horizontalCenter
width: img.sourceSize.width * imgScale
height: img.sourceSize.height * imgScale
Image {
id: img
anchors.fill: parent
source: item_img_path + "/" + Math.random()
fillMode: Image.Stretch
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.