qt - 为什么 SwipeView 组件不尊重 Item 模型属性?
问题描述
在我的应用程序中,我有一个带有图像和尺寸的项目
LanguageImage.qml
Item {
...
Image
{
width: 100
height: 100
id:imageFlag
anchors.fill: parent
fillMode: Image.PreserveAspectCrop
}
...
}
当我想在 SwipeView 中使用时,我把它们当作组件
main.qml
...
SwipeView
{
id:sliderImmagine
anchors.fill: parent
currentIndex: 0
clip:true
LanguageImage
{
id:italian
Image
{
width:100
height: 100
source: "/image/italy.jpg"
}
}
LanguageImage
{
id:spanish
Image
{
source: "/image/spain.jpg"
}
}
LanguageImage
{
id:french
Image
{
source: "/image/france.jpg"
}
}
}
但是这些项目不尊重我在项目类型中设置的尺寸。为什么这个?如果我在 SwipeView 组件中强制尺寸,那没关系。有解决方案还是我错了?
解决方案
如果您想提供对组件图像的访问,您必须执行以下操作:
Item {
property alias source: imageFlag.source
Image {
width: 100
height: 100
id:imageFlag
anchors.fill: parent
fillMode: Image.PreserveAspectCrop
}
}
现在您可以按如下方式使用它:
LanguageImage {
source: "/image/italy.jpg"
}
推荐阅读
- php - 带有 UploadId 和 PartNumber 的 AWS getSignedUrl
- c# - ASP.NET Core MVC 从查询中获取模型属性的属性
- java - 改造 API 调用(java)返回空对象
- powershell - SPN 和带有 Kerberos 的远程 Powershell - Hyper-V Vm
- javascript - 有没有办法在 React App 中添加一个不允许空输入的条件?
- powershell - ESpeakNG 语音合成器(在 PowerShell 中)无法识别 UTF-8 文本
- php - 如何在 phpdesktop-chrome 中嵌入 mysql
- latex - 同情符号$Delta x$
- javascript - 如何在不使用任何 npm 包的情况下在 react native 中制作自定义轮播或图像幻灯片
- angular - 如何从输入文件中删除重复文件(Angular)