gpt4 book ai didi

image - 如何在不破坏图像纵横比的情况下调整 QImage 或 QML 图像的大小以适合父容器

转载 作者:行者123 更新时间:2023-12-02 08:10:23 26 4
gpt4 key购买 nike

场景:
我有一个 Image QML 中的组件,其中包含 QImage不同的纵横比。

代码:

Window {
id: app_window
visible: true

Rectangle {
id: my_image_view_container
width: app_window.width
height: app_window.height

Image {
id: my_image
// changes at runtime based on the image my app selects
source: "random/path/to/an/image.jpg"
width: sourceSize.width
height: sourceSize.height
scale: Qt.KeepAspectRatio
}
}
}

问题:
我如何设置 width & heightmy_image_view_container以适合 my_image完全内部 my_image_view_container在不影响其纵横比的情况下?

最佳答案

您可以使用 fillMode 属性。
像这样

fillMode: Image.PreserveAspectFit

关于image - 如何在不破坏图像纵横比的情况下调整 QImage 或 QML 图像的大小以适合父容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47774118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com