qt - 如何禁用 QML 对象的可伸缩性
问题描述
如何禁用 QML 对象的可调整大小?我创建的对象的高度和宽度属性基于可缩放对象,但我不希望在调整父对象大小时调整对象大小。我如何实现这一目标?
Window {
id: window
visible: true
title: qsTr("Stack")
Component.onCompleted: {
window.showMaximized()
}
Rectangle {
width:parent.width/2
height:parent.height/2
}
}
使用上面的代码,矩形将创建为父级大小的 1/2,我希望它保持这种状态。当我调整窗口大小时,矩形也会调整大小,我希望它在创建后得到修复。我如何实现这一目标?谢谢你。
解决方案
删除您的属性绑定。
Window {
id: window
visible: true
title: qsTr("Stack")
Component.onCompleted: {
window.showMaximized()
rect.width = parent.width / 2; // use these
rect.height = parent.height / 2;
}
Rectangle {
id: rect
// width: parent.width/2 // no property bindings
// height: parent.height/2
}
}
rect.width
通过在and上使用属性绑定rect.height
,您可以使它们受到动态变化的影响。你不想要那个。相反,您可以从 Javascript 调用静态分配。
如果将 JS 代码放在 中Component.onCompleted
,它只会运行一次(不会在每次调整窗口大小时更新)。这些分配不会创建属性绑定、修复rect.width
和rect.height
.
推荐阅读
- php - PHP:在数据库中创建每 15 行的动态页面
- php - 从 .txt 文件中拆分条目并使用 php 从 for sitemap.xml 创建一个 foreach 循环
- c++ - 在 LeetCode 上编译后的运行时错误
- visual-studio-code - VSCode 中自动缩进代码的快捷方式是什么?
- .net - 尝试读取在 .NET 和 JVM 中生成的 RSA 公钥,但失败了
- r - 识别错误(x,y,标签 = 名称,绘图 = TRUE)
- arrays - 从 MongoDB 中的子文档聚合总计
- pine-script - 我如何确保在这个 pinescript 代码中没有信号重绘?
- javascript - 如何在一张幻灯片后停止滑动滑块自动播放
- python - 如何在某个索引处将列表添加到python中的另一个列表