场景:
我在QML中有一个包含各种宽高比的Image组件,其中包含一个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
}
}
}
问题:
如何设置my_image_view_container
的width
和height
,以便完全适应my_image
而不破坏其纵横比?