当前位置:网站首页>QML初学
QML初学
2022-07-07 15:32:00 【God港】
一、新建项目
1.选择Qt Quick Application Empty
2.命名为QmlDemoa,然后全部为下一步
3.此时工程目录和演示效果

二、新建另一个组件
1.选择QtQuick UI File
这里英文打错了:component1
2.当前工程的结构
3.设计新的qml的内容我们可以直接用qml.ui进行拖拽设计
本次演示我就用代码的方式进行添加。
工程目录中生成的component.qml和component1.ui.qml两个其实都可以用,qml可以调用ui中的任意元素,如果直接在ui中拖拽,会自动生成代码在ui.qml。当然我们代码可以写在任意文件,全凭个人喜好。
三、代码
component1.qml
import QtQuick 2.4
Rectangle {
property alias mouseArea:mouseArea
property alias topRect:topRect//define the property name
width: 360
height: 360//set form's width and height
MouseArea{
id:mouseArea//name
anchors.fill: parent
}
//the first rectangle
Rectangle{
rotation:45//define the rotation angle
//set the position,size and color
x:40
y:50
width: 100
height: 100
color: "blue"
}
//the second rectangle
Rectangle{
id:topRect//id
opacity: 0.5
scale: 0.8 //scale the size
x:135
y:60
width: 100
height: 100
radius: 8
gradient: Gradient{
GradientStop{
position: 0.0;color:"yellow"}
GradientStop{
position:1.0;color: "red"}
}
border{
width: 3;color: "green"}
}
}
main.qml
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Component1
{
}
}
四、总结
这样,一个简单的qml应用程序搭建完成,组件式开发现在事互联网很盛行的方式,曾经学习的VUE3大规模运用,好处在于耦合度较好,便于后期代码的维护,毕竟一个软件程序的声明周期,20%的时间在开发,80%的时间在维护。
五、效果图

demo下载地址:https://download.csdn.net/download/qq_38491692/85448974
边栏推荐
- 爬虫(17) - 面试(2) | 爬虫面试题库
- "The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."
- [designmode] facade patterns
- 谈谈 SAP 系统的权限管控和事务记录功能的实现
- Have fun | latest progress of "spacecraft program" activities
- AutoLISP series (1): function function 1
- [designmode] proxy pattern
- 预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
- 字节跳动Android面试,知识点总结+面试题解析
- 模块六
猜你喜欢

Have fun | latest progress of "spacecraft program" activities

Master this set of refined Android advanced interview questions analysis, oppoandroid interview questions

【C 语言】 题集 of Ⅹ

AutoLISP series (2): function function 2

Record the migration process of a project

The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit

【图像传感器】相关双采样CDS
![[C language] question set of X](/img/17/bfa57de183c44cf0a3c6637bb65a9d.jpg)
[C language] question set of X
ByteDance Android gold, silver and four analysis, Android interview question app

预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
随机推荐
Find tags in prefab in unity editing mode
[summary of knowledge] summary of notes on using SVN in PHP
Ray and OBB intersection detection
A tour of gRPC:03 - proto序列化/反序列化
AutoLISP series (1): function function 1
What is the difference between IP address and physical address
作为Android开发程序员,android高级面试
LeetCode 152. 乘积最大子数组 每日一题
Personal notes of graphics (2)
应用在温度检测仪中的温度传感芯片
3000 words speak through HTTP cache
LocalStorage和SessionStorage
掌握这套精编Android高级面试题解析,oppoAndroid面试题
最新2022年Android大厂面试经验,安卓View+Handler+Binder
数据中台落地实施之法
LeetCode 1031. 两个非重叠子数组的最大和 每日一题
编程模式-表驱动编程
如何选择合适的自动化测试工具?
[designmode] flyweight pattern
node:504报错