当前位置:网站首页>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
边栏推荐
- 字节跳动Android金三银四解析,android面试题app
- 【Vulnhub靶场】THALES:1
- 面试题 01.02. 判定是否互为字符重排-辅助数组算法
- LeetCode 403. 青蛙过河 每日一题
- 【PHP】PHP接口继承及接口多继承原理与实现方法
- Prometheus API deletes all data of a specified job
- Laravel post shows an exception when submitting data
- Lowcode: four ways to help transportation companies enhance supply chain management
- 水平垂直居中 方法 和兼容
- Vs2019 configuration matrix library eigen
猜你喜欢
3000 words speak through HTTP cache
使用JSON.stringify()去实现深拷贝,要小心哦,可能有巨坑
Sort out several important Android knowledge and advanced Android development interview questions
DNS 系列(一):为什么更新了 DNS 记录不生效?
AutoLISP series (1): function function 1
《产品经理必读:五种经典的创新思维模型》的读后感
Personal notes of graphics (1)
预测——灰色预测
水平垂直居中 方法 和兼容
掌握这个提升路径,面试资料分享
随机推荐
C语言进阶——函数指针
低代码(lowcode)帮助运输公司增强供应链管理的4种方式
整理几个重要的Android知识,高级Android开发面试题
[designmode] facade patterns
Laravel post shows an exception when submitting data
【医学分割】attention-unet
面试题 01.02. 判定是否互为字符重排-辅助数组算法
Opencv configuration 2019vs
第九届 蓝桥杯 决赛 交换次数
LocalStorage和SessionStorage
【C 语言】 题集 of Ⅹ
URL和URI的关系
二叉搜索树(基操篇)
01tire+ chain forward star +dfs+ greedy exercise one
Ray and OBB intersection detection
logback. XML configure logs of different levels and set color output
作为Android开发程序员,android高级面试
LeetCode 120. 三角形最小路径和 每日一题
LeetCode 1155. 掷骰子的N种方法 每日一题
01tire+链式前向星+dfs+贪心练习题.1