当前位置: 首页 > article >正文

Qt Quick快速入门笔记

Qt Quick快速入门笔记

  • 基本的程序结构
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endifQGuiApplication app(argc, argv);QQmlApplicationEngine engine;const QUrl url(QStringLiteral("qrc:/main.qml"));QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,&app, [url](QObject *obj, const QUrl &objUrl) {if (!obj && url == objUrl)QCoreApplication::exit(-1);}, Qt::QueuedConnection);// 引擎加载qmlengine.load(url);return app.exec();
}
import QtQuick 2.12
import QtQuick.Window 2.12Window {width: 640height: 480visible: truetitle: qsTr("Hello World")
}
  • Window

查看qml渲染效果

选中对应qml-> 顶部工具 ->外部-> Qt Quick -> Qt Qucik Preview

基础组件体验

Item

Item是Qt Quick所有可视元素的基类,定义了大部分属性,包括。x,y,z,width,height,anchors,按键响应等。可以将多个Item嵌套在一起形成复杂界面布局.z数值越大,越在图层上面

Item {focus: true// 回车按键响应Keys.onReturnPressed: console.log("Pressed return");
}

Rectangle

矩形区域,提供颜色、边框、圆角属性等

Rectangle {width: 100height: 100color: "red"// color: Qt.rgba(0.4,0.5,0.8,1)border.color: "black"border.width: 5radius: 10anchors.centerIn: parentComponent.onCompleted:{console.log("Rectangle Completed!")}}

anchors 锚布局

指定控件与其他控件之间的位置关系centerIn、left、right、top、bottom、horizontalCenter、verticalCenter等

Rectangle {id: testwidth: 100height: 100color: Qt.rgba(0.4,0.5,0.8,1)border.color: "black"border.width: 5radius: 10anchors.centerIn: parent}Button {// Button 左边靠着Rectangle 间隔20,顶部y持平anchors.left: test.rightanchors.leftMargin: 20anchors.top: test.toptext: "Ok"onClicked: console.log("click button")
}

Text

Text支持多种文本格式html、markdown

Text {text: "Hello World!"font.family: "Helvetica"color: "red"// 字体自适应fontSizeMode: Text.Fitfont.pixelSize:  50 // 字体最大尺寸minimumPixelSize: 12 // 字体最小尺寸
}

Label

Label
{id: usernamefont.pixelSize: 22font.italic: truecolor: "steelblue"text: "账号:"
}

TextField

TextField
{placeholderText: "请输入用户名"x: 10y: 10background: Rectangle{implicitHeight: 40implicitWidth: 200color: "red"border.color: "black"}// 密码样式echoMode: TextInput.Password
}

TextInput

TextInput与TextField类似

TextInput没有背景是透明的

TextField有背景色

MouseArea {anchors.fill: parentonClicked: () => {// 获取验证结果console.log("result = ", testValidator.acceptableInput)}
}TextInput
{id: testValidatorx: 10y: 10width: 100height: 30// 验证输入validator: IntValidator{ bottom: 100; top: 999}
}

TextEdit

MouseArea {anchors.fill: parentonClicked: () => {console.log("selectionStart = ", edit.selectionStart)console.log("selectionEnd = ", edit.selectionEnd)console.log("selectedText = ", edit.selectedText)// 搜索文本var tex = edit.getText(0, edit.text.length)console.log("tex = ", tex)let index = tex.indexOf("el")console.log("index = ", index)}
}TextEdit {id: editwidth: 240text: "<b>Hello</b> <i>World!</i>"font.family: "Helvetica"font.pointSize: 20color: "blue"focus: true// persistentSelection: true
}

TextArea

TextArea
{x: 10y: 20background: Rectangle{implicitWidth: 100implicitHeight: 80border.color: "blue"border.width: 2}placeholderText: "请输入多行文本"font.pixelSize: 18color: "red"
}// 滚动条
ScrollView {width: 100height: 200TextArea{x: 10y: 20background: Rectangle{implicitWidth: 100implicitHeight: 80border.color: "blue"border.width: 2}placeholderText: "请输入多行文本"font.pixelSize: 18color: "red"}
}

Button

Button系列包括:CheckBox(勾选框)、DelayButton(延时按钮)、RadioButton(单选框)、RoundButton(圆形按钮)、Switch(开关)、ToolButton

Button {anchors.centerIn: parenttext: "Ok"onClicked: console.log("click button")
}// buttonStyle案例
Component {id: mystyle// 自定义按钮外观ButtonStyle {background: Rectangle {implicitHeight: 45implicitWidth: 150radius: 10border.width: 2border.color: "red"//color: "blue"}}Button {text: "测试数据"style: mystyle}
}

CheckBox

// CheckBox 示例
Rectangle
{width: 150height: 100color: "yellow"border.color: "orange"border.width: 2CheckBox {x: 0y: 0text: "JavaScript"onCheckedChanged:{console.log("status = ", checked)}}CheckBox {x: 0y: 40text: "java"}
}// 互斥单选box
ButtonGroup
{id: testButtonGroupexclusive: true
}
CheckBox {ButtonGroup.group: testButtonGroupx: 0y: 0text: "JavaScript"
}CheckBox {ButtonGroup.group: testButtonGroupx: 0y: 40text: "java"
}

Repeater

Column
{spacing: 10width: 100height: 400anchors.centerIn: parentRepeater{id: testRepeatermodel: 5property var titles: ["ID:", "姓名", "班级"]property var values: ["02220455", "张三", "6班"]Row{spacing: 3Text {text: testRepeater.titles[index]color: "black"font: {bold: truepointSize: 16}}Text {text: testRepeater.values[index]color: "red"font: {bold: truepointSize: 16}}}}
}

GroupBox

GroupBox用于组织和分组其他控件的容器

Item {width: 300height: 200anchors.centerIn: parentGroupBox{title: "groupbox"anchors.centerIn: parentwidth: 250height: 180CheckBox {x: 0y: 0text: "JavaScript"}CheckBox {x: 0y: 40text: "java"}}
}

RadioButton

Item {width: 300height: 200anchors.centerIn: parentGroupBox{title: "groupbox"anchors.centerIn: parentwidth: 250height: 180RadioButton {x: 0y: 0text: "JavaScript"}RadioButton {x: 0y: 40text: "java"}}
}

Slider

Rectangle {width: 100height: 500Slider {id: sliderfrom: 1value: 25to: 100}MouseArea{anchors.fill: parentonClicked: () => {console.log("value = " , slider.value.toFixed(2))// position 范围是0-1console.log("position = " , slider.position)}}
}

Image

// 加载本地图片
Image {asynchronous: truesource: "qrc:/03.png"  // qrc中的图片资源
}// 充满父视图的背景
Image {anchors.fill: parentsource: ":/test/333.jpg"  // qrc中的图片资源}// 网络图片
Image {id: imageViewwidth: 100height: 40asynchronous: truesource: "http://www.baidu.com/img/pcdoodle_2a77789e1a67227122be09c5be16fe46.png"//fillMode: Image.PreserveAspectCroponStatusChanged:{console.log("imageView statu = ", imageView.status)}
}

BusyIndicator

// 加载器
// 图片还在加载的时候显示加载器
BusyIndicator {running: imageView.status === Image.Loadinganchors.centerIn: parent}Image {id: imageViewwidth: 100height: 40asynchronous: truesource: "http://www.baidu.com/img/pcdoodle_2a77789e1a67227122be09c5be16fe46.png"//fillMode: Image.PreserveAspectCroponStatusChanged:{console.log("imageView statu = ", imageView.status)}
}

FileDialog

FileDialog {id: fileDialogtitle: "Please choose a file"folder: shortcuts.homeonAccepted: {console.log("You chose: " + fileDialog.fileUrls)}onRejected: {console.log("Canceled")}
}Button
{text: "打开"onClicked: fileDialog.visible = true
}

ComboBox

ComboBox {// 默认选择currentIndex: 2displayText: "语言: " + currentTextmodel: ["java", "javaScript", "C++"]
}ComboBox {id: boxanchors.centerIn: parenttextRole: "key"valueRole: "value"model: ListModel{id: modelDataListElement {key: "first"; value: 1}ListElement {key: "second"; value: 2}ListElement {key: "third"; value: 3}}onActivated: (index) => {print("onActivated ", index)print("currentIndex ", currentIndex)print("currentValue ", currentValue)print("currentText ", currentText)}
}Button
{text: "删除"anchors.top: box.bottomanchors.topMargin: 10anchors.horizontalCenter: parent.horizontalCenteronClicked:{modelData.remove(box.currentIndex, 1)}
}

ListView

Rectangle {id: topViewwidth: 400height: 300color: "red"ScrollView{// 滚动条anchors.fill: parentListView{id: listViewanchors.fill: parentmodel:  ListModel{id: listDataListElement{name: "first"number: "123"}ListElement{name: "second"

相关文章:

Qt Quick快速入门笔记

Qt Quick快速入门笔记 基本的程序结构int main(int argc, char *argv[]) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endifQGuiApplication app(argc, argv);QQmlApplicationEngine engine;const QUrl ur…...

《波段操盘实战技法》速读笔记

文章目录 书籍信息概览实战八法波段见顶信号中长线大顶形态投资理念 书籍信息 书名&#xff1a;《波段操盘实战技法》 作者&#xff1a;何瑞东 概览 实战八法 投资理念和投资理论概述&#xff1a;波段操作的核心是通过捕捉股价波动中的趋势性机会&#xff0c;结合技术分析与…...

Glide NoResultEncoderAvailableException异常解决

首先将解决方法提出来&#xff1a;缓存策略DiskCacheStrategy.DATA。 使用Glide加载图片&#xff0c;版本是4.15.0&#xff0c;有天发现无法显示gif图片&#xff0c;原始代码如下&#xff1a; Glide.with(context).load(本地资源路径).diskCacheStrategy(DiskCacheStrategy.A…...

工厂模式与多态结合

工厂模式与多态的结合是平台化项目中实现灵活架构的核心技术之一。这种组合能够创建可扩展、易维护的系统架构。 多态(Polymorphism)指同一操作作用于不同的对象&#xff0c;可以有不同的解释&#xff0c;产生不同的执行结果。 例子1&#xff1a; public abstract class Pay…...

无人机巡检智能边缘计算终端技术方案‌‌——基于EFISH-SCB-RK3588工控机/SAIL-RK3588核心板的国产化替代方案‌

一、方案核心价值‌ ‌实时AI处理‌&#xff1a;6TOPS NPU实现无人机影像的实时缺陷检测&#xff08;延迟&#xff1c;50ms&#xff09;‌全国产化‌&#xff1a;芯片、操作系统、算法工具链100%自主可控‌极端环境适配‌&#xff1a;-40℃~85℃稳定运行&#xff0c;IP65防护等…...

相机--相机成像原理和基础概念

教程 成像原理 基础概念 焦距&#xff08;物理焦距&#xff09; 镜头的光学中心到感光元件之间的距离&#xff0c;用f表示&#xff0c;单位&#xff1a;mm&#xff1b;。 像素焦距 相机内参矩阵中的 fx​ 和 fy​ 是将物理焦距转换到像素坐标系的产物&#xff0c;可能不同。…...

2025-0604学习记录17——文献阅读与分享(2)

最近不是失踪了&#xff01;也不是弃坑了...这不是马上要毕业了嘛&#xff01;所以最近在忙毕业论文答辩、毕业去向填报、户档去向填报等等&#xff0c;事情太多了&#xff0c;没顾得上博客。现在这些事基本上都解决完了&#xff0c;也有时间静下心来写写文字了~ 想要写的内容…...

图解浏览器多进程渲染:从DNS到GPU合成的完整旅程

目录 浅谈浏览器进程 浏览器进程架构的演化 进程和线程关系图示 进程&#xff08;Process&#xff09; 线程&#xff08;Thread&#xff09; 协程&#xff08;Coroutine&#xff09; 进程&线程&协程核心对比 单进程和多进程浏览器 单进程浏览器​编辑 单进程…...

【计算机网络】第3章:传输层—TCP 拥塞控制

目录 一、PPT 二、总结 TCP 拥塞控制详解 ⭐ 核心机制与算法 1. 慢启动&#xff08;Slow Start&#xff09; 2. 拥塞避免&#xff08;Congestion Avoidance&#xff09; 3. 快速重传&#xff08;Fast Retransmit&#xff09; 4. 快速恢复&#xff08;Fast Recovery&…...

idea不识别lombok---实体类报没有getter方法

介绍 本篇文章&#xff0c;主要讲idea引入lombok后&#xff0c;在实体类中加注解Data&#xff0c;在项目启动的时候&#xff0c;编译不通过&#xff0c;报错xxx.java没有getXxxx&#xff08;&#xff09;方法。 原因有以下几种 1. idea没有开启lombok插件 2. 使用idea-2023…...

【Hive入门】

之前实习写的笔记&#xff0c;上传留个备份。 1. 使用docker-compose快速搭建Hive集群 使用docker快速配置Hive环境 拉取镜像 2. Hive数据类型 隐式转换&#xff1a;窄的可以向宽的转换显式转换&#xff1a;cast 3. Hive读写文件 SerDe:序列化&#xff08;对象转为字节码…...

亚马逊站内信规则2025年重大更新:避坑指南与合规策略

亚马逊近期对Buyer-Seller Messaging&#xff08;买家-卖家站内信&#xff09;规则进行了显著收紧&#xff0c;明确将一些曾经的“灰色操作”列为违规。违规操作轻则收到警告&#xff0c;重则导致账户暂停或绩效受限。本文为您全面解析本次规则更新的核心要点、背后逻辑&#x…...

01 - AI 时代的操作系统课 [2025 南京大学操作系统原理]

01 - AI 时代的操作系统课 [2025 南京大学操作系统原理] [00:00:00]-[D:\movie\南京大学操作系统\01-AI时代的操作系统课[2025南京大学操作系统原理].mp4] 大家好&#xff01;我是姜艳艳&#xff0c;来自南京大学计算机软件研究所。今天我们开启《操作系统原理》的第一课&…...

数组1 day7

六&#xff1a;数组 一&#xff1a;数据类型 1.int a[10] //想要知道一个标识符对应的数据类型&#xff0c;去掉标识符&#xff0c;剩下就是它对应的数据类型 ​ //eg&#xff1a;a所谓代表的类型&#xff0c;就是int[10]这种类型&#xff08;是一个数组&#xff0c;包含10个…...

SAP学习笔记 - 开发15 - 前端Fiori开发 Boostrap,Controls,MVC(Model,View,Controller),Modules

上一章讲了Fiori开发的准备&#xff0c;以及宇宙至简之HelloWorld。 SAP学习笔记 - 开发14 - 前端Fiori开发 HelloWorld-CSDN博客 本章继续学习 Fiori 开发的知识&#xff1a; Bootstrap&#xff0c;Controls&#xff0c;MVC(Model&#xff0c;View&#xff0c;Controller&a…...

Redis中的过期策略与内存淘汰策略

因为Redis是纯内存操作&#xff0c;所以在Redis中创建的键一般都会带有过期时间&#xff0c;以此来保证内存中存储数据的时效性。这篇文章我们就来讲解一下Redis中的过期策略与内存淘汰策略。 如何设置Redis中键的过期时间&#xff1f; Redis提供了4个命令来设置键的过期时间&…...

基于SDN环境下的DDoS异常攻击的检测与缓解

参考以下两篇博客&#xff0c;最后成功&#xff1a; 基于SDN的DDoS攻击检测和防御方法_基于sdn的ddos攻击检测与防御-CSDN博客 利用mininet模拟SDN架构并进行DDoS攻击与防御模拟&#xff08;Ryumininetsflowpostman&#xff09;_mininet模拟dos攻击-CSDN博客 需求 H2 模拟f…...

HarmonyOS 实战:给笔记应用加防截图水印

最近在做笔记类应用时&#xff0c;遇到一个头疼的需求&#xff1a;防止用户内容被非法截图传播。思来想去&#xff0c;加水印是个直接有效的方案。研究了 HarmonyOS 的开发文档后&#xff0c;发现用 Canvas 配合布局组件能轻松实现动态水印效果。今天就来聊聊如何给笔记页面加上…...

如何轻松地将文件从 PC 传输到 iPhone?

传统上&#xff0c;您可以使用 iTunes 将文件从 PC 传输到 iPhone&#xff0c;但现在&#xff0c;使用 iTunes 已不再是唯一的选择。现在有多种不同且有效的方法可以帮助您传输文件。在今天的指南中&#xff0c;您可以找到 8 种使用或不使用 iTunes 传输文件的方法&#xff0c;…...

前端面试二之运算符与表达式

目录 1.JavaScript 中的 和 运算符 2.|| (逻辑或) 运算符 与 ES6 默认参数的区别 与 ?? (空值合并运算符) 的区别 3.?.&#xff08;可选链&#xff09;运算符 (1). 安全访问深层嵌套属性 (2). 安全调用可能不存在的函数 (3). 安全访问数组元素 4.展开运算符 (..…...

【运维实战】使用Nvm配置多Node.js环境!

背景 新项目 使用Node.js-v16.17.1旧项目 使用Node.js- v14.18.0 【且依赖于node-saas模块&#xff0c;根据 node-sass 的官方文档&#xff0c;目前最新版本的 node-sass&#xff08;即 v5.0.0&#xff09;支持的 Node.js 版本范围是 Node.js 10.x、Node.js 12.x、Node.js 14.…...

Bresenham算法

一 Bresenham 绘直线 使用 Bresenham 算法&#xff0c;可以在显示器上绘制一直线段。该算法主要思想如下&#xff1a; 1 给出直线段上两个端点 &#xff0c;根据端点求出直线在X,Y方向上变化速率 &#xff1b; 2 当 时&#xff0c;X 方向上变化速率快于 Y 方向上变化速率&am…...

【从GEO数据库批量下载数据】

从GEO数据库批量下载数据 1&#xff1a;进入GEO DataSets拿到所需要下载的数据的srr.list&#xff0c;上传到linux&#xff0c; 就可以使用prefetch这个函数来下载 2&#xff1a;操作步骤如下&#xff1a; conda 安装sra-tools conda create -n sra-env -c bioconda -c co…...

day 44

使用DenseNet预训练模型对cifar10数据集进行训练 import torch import torch.nn as nn import torch.optim as optim from torchvision import datasets, transforms, models from torch.utils.data import DataLoader import matplotlib.pyplot as plt import os# 设置中文字体…...

鸿蒙OSUniApp开发跨平台AR扫描识别应用:HarmonyOS实践指南#三方框架 #Uniapp

UniApp开发跨平台AR扫描识别应用&#xff1a;HarmonyOS实践指南 前言 随着增强现实&#xff08;AR&#xff09;技术在移动应用中的广泛应用&#xff0c;越来越多的开发者需要在跨平台应用中实现AR功能。本文将深入探讨如何使用UniApp框架开发一个高性能的AR扫描识别应用&…...

NER实践总结,记录一下自己实践遇到的各种问题。

更。 没卡&#xff0c;跑个模型休息好几天&#xff0c;又闲又急。 一开始直接套用了别人的代码进行实体识别&#xff0c;结果很差&#xff0c;原因是他的词表没有我需要的东西&#xff0c;我是用的医学文本。代码直接在github找了改的&#xff0c;用的是BERT的Chinese版本。 然…...

微信小程序实现运动能耗计算

微信小程序实现运动能耗计算 近我做了一个挺有意思的微信小程序&#xff0c;能够实现运动能耗的计算。只需要输入性别、年龄、体重、运动时长和运动类型这些信息&#xff0c;就能算出对应的消耗热量。 具体来说&#xff0c;在小程序里&#xff0c;性别不同&#xff0c;身体基…...

iTunes 无法备份 iPhone:10 种解决方法

Apple 设备是移动设备市场上最先进的产品之一&#xff0c;但有些人遇到过 iTunes 因出现错误而无法备份 iPhone 的情况。iTunes 拒绝备份 iPhone 时&#xff0c;可能会令人非常沮丧。不过&#xff0c;幸运的是&#xff0c;我们有 10 种有效的方法可以解决这个问题。您可以按照以…...

施耐德特价型号伺服电机VIA0703D31A1022、常见故障

⚙️ ‌一、启动类故障‌ ‌电机无法启动‌ ‌可能原因‌&#xff1a;电源未接通、制动器未释放、接线错误或控制器故障。‌解决措施‌&#xff1a; 检查电源线路及断路器状态&#xff1b;验证制动器是否打开&#xff08;带制动器型号&#xff09;&#xff1b;核对电机与控制器…...

LangChain4J 使用实践

这里写目录标题 大模型应用场景&#xff1a;创建一个测试示例AIService聊天记忆实现简单实现聊天记录记忆MessageWindowChatMemory实现聊天记忆 隔离聊天记忆聊天记忆持久化 添加AI提示词 大模型应用场景&#xff1a; 创建一个测试示例 导入依赖 <dependency><groupI…...