qt - 用于方向更改的 QML 信号完成
问题描述
我正在为 iPad 开发 ESRI AppStudio 应用程序(AppStudio 3.1,Qt 5.11),并且需要在方向更改时对 QML 控件进行一些调整大小。我发现这个页面似乎描述了执行此操作的官方方式:https ://wiki.qt.io/QML_orientation_observer
import QtQuick.Window 2.2
Rectangle {
property bool isPortrait: Screen.primaryOrientation === Qt.PortraitOrientation || Screen.primaryOrientation === Qt.InvertedPortraitOrientation
onIsPortraitChanged: console.log("isPortrait", isPortrait)
}
但是,我发现该页面上关于在完成高度和宽度更改后将触发绑定的声明是不正确的。我在实现时看到的是 onIsPortraitChanged 在方向改变时确实会触发,但它会在方向改变动画完成之前和调整应用程序的宽度之前触发。有没有办法在宽度完成更改后触发我的代码?
解决方案
这是我找到的一个解决方案,但它仅适用于应用程序全屏的设备,并且可能有更简洁的方法来执行此操作。
import QtQuick.Window 2.2
Window {
id: app
visible: true
width: 640
height: 480
Rectangle {
anchors.fill: parent
onWidthChanged: {
if(app.width === Screen.width || app.width === Screen.height) {
//calculate new size
}
}
}
}
推荐阅读
- python - 使用for循环在字典中嵌套字典迭代
- r - 从具有上限/下限的泊松分布中抽取的样本数
- java - Eclipse 在错误的目录中创建 JUnit 测试
- python - 如何加速算法以找到时间重叠?
- plsql - 在 PL/SQL 代码中出现“编译单元分析终止”错误
- python - 如何在 Pandas 中对一列列表(考虑列表中的每个项目)执行条件
- javascript - 单击编辑按钮不会更改表格过滤后页面上的 html
- r - 有没有办法以不同的方式处理第一个 lapply 元素?或将其添加到 lapply 结果中?
- swift - 调整元素大小以适应 spritekit 中的屏幕大小
- excel - 除非特定工作表处于活动状态,否则 VBA 代码不起作用