QML实战

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

Models and Views in Qt Quick


5 动态创建QML对象

在StackLayout中动态添加子对象

var component = Qt.createComponent("OrderList.qml");

 if (component.status === Component.Ready) {

              component.createObject(stackLayout); // 创建对象,并指定父级, stackLayout为 StackLayout对象的id

              stackLayout.currentIndex = 1

 }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • (基于qt 5.3.1) 一、Qt Quick入门 1.启动Qt Quick App的两种方式窗口标题、图标等由q...
    素理想阅读 3,979评论 0 4
  • 界面 主窗口界面设计 标题栏:直接设Window-Title属性;Window-icon属性可加图标。底部状态栏:...
    码园老农阅读 3,819评论 1 13
  • 1.初识 Qt5 本书将为大家介绍使用 Qt 5.x 版本开发应用程序的不同方面。我们将专注于新的 Qt Quic...
    赵者也阅读 2,620评论 0 8
  • 1. 首先编写好C++类 #include class Cpp : public QObject{ Q_OBJ...
    Gwkang阅读 1,315评论 0 0
  • 在使用QML做移动端开发时,我们总是会接触到多媒体的开发,尤其在当下这个流媒体时代,拍小视频已经成为了一种...
    沐络阅读 1,748评论 0 0