1 问题
QQmlExpression: Expression qrc:/Login.qml:26:17 depends on non-NOTIFYable properties:
任何属性都要关联NOTIFY信号,不然在初始化完成后,任何对属性的修改都不会更新。
2 元素的长宽设置问题
想让元素的长宽随父级变化,但是使用了 anchors.fill: parent后,元素的大小不会随父级变化
Component {
id: mainPage
MainPage{
// anchors.fill: parent // 当使用此设置时,对象的长宽不会随父级改变
width: parent.width
height: parent.height
}
}
3 window大小改变监听
当窗口大小改变时,可以通过捕获QWindow的两个信号:widthChanged 和 heightChanged来处理
Connections {
target: mWindow
onHeightChanged: {
console.log('window height change')
console.log('height:', mWindow.height)
pageLoader.height = mWindow.height
}
onWidthChanged: {
console.log('window width change')
console.log('width:', mWindow.width)
pageLoader.width = mWindow.width
}
}
4 ListView
Using C++ Models with Qt Quick Views
5 动态创建QML对象
在StackLayout中动态添加子对象
var component = Qt.createComponent("OrderList.qml");
if (component.status === Component.Ready) {
component.createObject(stackLayout); // 创建对象,并指定父级, stackLayout为 StackLayout对象的id
stackLayout.currentIndex = 1
}