Learning Qt 5! (20):QML

新的语言——QML!
一个很棒的学习QML的网站QmlBook!
Qt 学习之路 2(76):QML 和 QtQuick 2
Qt 学习之路 2(77):QML 语法
Qt 学习之路 2(78):QML 基本元素
Qt 学习之路 2(79):QML 组件
Qt 学习之路 2(80):定位器
Qt 学习之路 2(81):元素布局
Qt 学习之路 2(82):输入元素
Qt 学习之路 2(83):Qt Quick Controls

从 Qt 4.7 开始,Qt 引入 QML(Qt Meta Language 或者 Qt Modeling Language),作为 C++ 语言的一种替代。QML 是一种基于 JavaScript 的声明式语言。在 Qt 5 中,QML 已经不仅限于开发手机应用,也可以用户开发传统的桌面程序。 Qt Quick 就是使用 QML 构建的一套类库。

QML 基本元素可以分为可视元素和不可视元素两类。可视元素(例如前面提到过的Rectangle)具有几何坐标,会在屏幕上占据一块显示区域。不可视元素(例如Timer)通常提供一种功能,这些功能可以作用于可视元素。
最基本的几种可视元素包括:Item、Rectangle、Text、Image和MouseArea。

QML 可以由这些基本元素组合成一个复杂的元素,方便以后我们的重用。这种组合元素就被称为组件。基于文件的组件将 QML 元素放置在一个单独的文件中,然后给这个文件一个名字。以后我们就可以通过这个名字来使用这个组件。例如,如果有一个文件名为 Button.qml,那么,我们就可以在 QML 中使用Button { … }这种形式。

QML 提供了很多用于定位的元素。这些元素叫做定位器,都包含在 QtQuick 模块。这些定位器主要有 Row、Column、Grid和Flow等。

除了定位器,QML 还提供了另外一种用于布局的机制。我们将这种机制成为锚点(anchor)。锚点允许我们灵活地设置两个元素的相对位置。它使两个元素之间形成一种类似于锚的关系,也就是两个元素之间形成一个固定点。锚点的行为类似于一种链接,它要比单纯地计算坐标改变更强。由于锚点描述的是相对位置,所以在使用锚点时,我们必须指定两个元素,声明其中一个元素相对于另外一个元素。锚点是Item元素的基本属性之一,因而适用于所有 QML 可视元素。

作为输入元素的MouseArea,用于接收鼠标的输入。用于键盘输入的是TextInput和TextEdit。TextInput是单行的文本输入框,支持验证器、输入掩码和显示模式等;TextEdit则是多行的文本编辑组件。

Qt Quick Controls这个模块提供了大量类似 Qt Widgets 模块那样可重用的组件。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Learn the fundamentals of QT 5 framework to develop interactive cross-platform applications Key Features A practical guide on the fundamentals of application development with QT 5 Learn to write scalable, robust and adaptable C++ code with QT Deploy your application on different platforms such as Windows, Mac OS, and Linux Book Description Qt is a mature and powerful framework for delivering sophisticated applications across a multitude of platforms. It has a rich history in the Linux world, is widely used in embedded devices, and has made great strides in the Mobile arena over the past few years. However, in the Microsoft Windows and Apple Mac OS X worlds, the dominance of C#/.NET and Objective-C/Cocoa means that Qt is often overlooked. This book demonstrates the power and flexibility of the Qt framework for desktop application development and shows how you can write your application once and deploy it to multiple operating systems. Build a complete real-world line of business (LOB) solution from scratch, with distinct C++ library, QML user interface, and QtTest-driven unit-test projects. This is a suite of essential techniques that cover the core requirements for most LOB applications and will empower you to progress from a blank page to shipped application. What you will learn Install and configure the Qt Framework and Qt Creator IDE Create a new multi-project solution from scratch and control every aspect of it with QMake Implement a rich user interface with QML Learn the fundamentals of QtTest and how to integrate unit testing Build self-aware data entities that can serialize themselves to and from JSON Manage data persistence with SQLite and CRUD operations Reach out to the internet and consume an RSS feed Produce application packages for distribution to other users Who This Book Is For This book is for application developers who want a powerful and flexible framework to create modern, responsive applications on Microsoft Windows, Apple Mac OS X, and Linux desktop platforms. You should be comfortable with C++ but no prior knowledge of Qt or QML is required. Table of Contents Install the Qt Framework and Qt Creator IDE Create a new solution and sub projects ready for application development. UX layout and navigation Styling QML and adding custom components Implement self aware data entities and JSON serialisation Unit testing our data entities Persist our data in a SQLite database Connect to the internet and consume a RSS feed Create a customised installation package for our application

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值