qt - QuickControls2 图像不会拉伸到父级的全宽
问题描述
我有一个简单的 QuickControls2 QML 设计,其中图像应水平拉伸以填充应用程序窗口并保持其纵横比。但是当我运行我的程序时,图像不会缩放/拉伸。
是图像小于当前窗口大小并且 QT 没有放大/增加图像大小的问题吗?是否有设置让 QT 调整图像大小以填充宽度而不考虑图像大小?
你能告诉我什么是错的,我该如何解决?
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ApplicationWindow {
id: applicationWindow
visible: true
width: 640
height: 480
title: qsTr("Scroll")
ColumnLayout {
id: mainLayout
anchors.fill: parent
Image {
id: imagePane
Layout.fillWidth: true
fillMode: Image.PreserveAspectFit
source: "placeholder.jpg"
}
}
}
解决方案
尝试这个:
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ApplicationWindow {
id: applicationWindow
visible: true
width: 640
height: 480
title: qsTr("Scroll")
ColumnLayout {
id: mainLayout
anchors.fill: parent
Image {
id: imagePane
Layout.preferredWidth: parent.width
Layout.preferredHeight: parent.height
fillMode: Image.PreserveAspectFit
source: "placeholder.jpg"
}
}
}
推荐阅读
- python - 如何通过使用 itemgetter 的列表值对字典进行排序?
- python - 如何从我的列表和python中的元组中删除空白引号?
- xamarin - Azure Devops 构建失败:未找到具有提供的指纹的证书
- javascript - 我如何在不和谐 v12 中列出角色中的所有成员?
- python - cadytsiterate.py 的输入是什么?
- dataframe - 如何过滤朱莉娅数据框?
- kotlin - 如何找到默认的 kotlin 编译器参数值?
- r - R语言定义:使用美元符号索引命名向量
- python - 通过操作 pyvenv.cfg 部署烧瓶,包括创建的 venv
- java - 尝试运行 jar 文件时出现 java.lang.UnsatisfiedLinkError