QML视图元素  Visual Elements In QML Qt 5.6.0 Reference Documentation

2024-06-16 10:32

本文主要是介绍QML视图元素  Visual Elements In QML Qt 5.6.0 Reference Documentation,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Qt 5.6
Use Case - Visual Elements In QML
Qt 5.6.0 Reference Documentation
Contents
The Rectangle Type
The Image Type
Shared Visual Properties
Opacity and Visibility
Transforms
Use Case - Visual Elements In QML
The Rectangle Type 矩形类型

For the most basic of visuals, Qt Quick provides a Rectangle type to draw rectangles矩形. These rectangles can be colored with a color or a vertical 垂直 gradient 倾斜度. The Rectangle type can also draw borders on the rectangle.
For drawing custom shapes beyond rectangles, see the Canvas type or display a pre-rendered image using the Image type.

import QtQuick 2.3

Item {

  width: 320height: 480Rectangle {color: "#272822"width: 320height: 480}// This element displays a rectangle with a gradient and a border 右边的Rectangle {x: 160y: 20width: 100height: 100radius 半径: 8 // This gives rounded corners to the Rectanglegradient 倾斜度: Gradient { // This sets a vertical gradient fillGradientStop { position: 0.0; color: "aqua" }GradientStop { position: 1.0; color: "teal" }}border 边框{ width: 3; color: "white" } // This sets a 3px wide black border to be drawn}// This rectangle is a plain color with no border 左边的Rectangle {x: 40y: 20width: 100height: 100color: "red"}

}

The Image Type 图像类型
Qt Quick provides an Image type which may be used to display images. The Image type has a source property whose value can be a remote or local URL, or the URL of an image file embedded in a compiled resource file.

// This element displays an image. Because the source is online, it may take some time to fetch
Image {
x: 40
y: 20
width: 61
height: 73
source: “http://codereview.qt-project.org/static/logo_qt.png”
}

For more complex images there are other types similar to Image. BorderImage draws an image with grid scaling 缩放比例, suitable for images used as borders边框图像. AnimatedImage plays animated .gif and .mng images播放动画图像. AnimatedSprite and SpriteSequence play animations comprised of multiple frames stored adjacently 多帧邻接存储的 in a non animated image format 不动的图像格式.
For displaying video files and camera data, see the Qt Multimedia module.多媒体模块
Shared Visual Properties
All visual items provided by Qt Quick are based on the Item type, which provides a common set of attributes for visual items, including opacity 不透明的 and transform 变化的 attributes.
Opacity and Visibility
The QML object types provided by Qt Quick have built-in support for opacity. Opacity can be animated to allow smooth transitions to or from a transparent state. Visibility can also be managed with the visible property more efficiently, but at the cost of not being able to animate it.

import QtQuick 2.3

Item {

  width: 320height: 480Rectangle {color: "#272822"width: 320height: 480}Item {x: 20y: 270width: 200height: 200MouseArea {anchors.fill: parentonClicked: topRect.visible = !topRect.visible}Rectangle {x: 20y: 20width: 100height: 100color: "red"}Rectangle {id: topRectopacity: 0.5x: 100y: 100width: 100height: 100color: "blue"}}

}

Transforms
Qt Quick types have built-in support for transformations. If you wish to have your visual content rotated or scaled, you can set the Item::rotation or Item::scale property. These can also be animated.

import QtQuick 2.3

Item {

  width: 320height: 480Rectangle {color: "#272822"width: 320height: 480}Rectangle {rotation: 45 // This rotates the Rectangle by 45 degreesx: 20y: 160width: 100height: 100color: "blue"}Rectangle {scale: 0.8 // This scales the Rectangle down to 80% sizex: 160y: 160width: 100height: 100color: "green"}

}

For more complex transformations, see the Item::transform property.

这篇关于QML视图元素  Visual Elements In QML Qt 5.6.0 Reference Documentation的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1066220

相关文章

使用C++实现链表元素的反转

《使用C++实现链表元素的反转》反转链表是链表操作中一个经典的问题,也是面试中常见的考题,本文将从思路到实现一步步地讲解如何实现链表的反转,帮助初学者理解这一操作,我们将使用C++代码演示具体实现,同... 目录问题定义思路分析代码实现带头节点的链表代码讲解其他实现方式时间和空间复杂度分析总结问题定义给定

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加

在MyBatis的XML映射文件中<trim>元素所有场景下的完整使用示例代码

《在MyBatis的XML映射文件中<trim>元素所有场景下的完整使用示例代码》在MyBatis的XML映射文件中,trim元素用于动态添加SQL语句的一部分,处理前缀、后缀及多余的逗号或连接符,示... 在MyBATis的XML映射文件中,<trim>元素用于动态地添加SQL语句的一部分,例如SET或W

基于Qt Qml实现时间轴组件

《基于QtQml实现时间轴组件》时间轴组件是现代用户界面中常见的元素,用于按时间顺序展示事件,本文主要为大家详细介绍了如何使用Qml实现一个简单的时间轴组件,需要的可以参考下... 目录写在前面效果图组件概述实现细节1. 组件结构2. 属性定义3. 数据模型4. 事件项的添加和排序5. 事件项的渲染如何使用

基于Qt开发一个简单的OFD阅读器

《基于Qt开发一个简单的OFD阅读器》这篇文章主要为大家详细介绍了如何使用Qt框架开发一个功能强大且性能优异的OFD阅读器,文中的示例代码讲解详细,有需要的小伙伴可以参考一下... 目录摘要引言一、OFD文件格式解析二、文档结构解析三、页面渲染四、用户交互五、性能优化六、示例代码七、未来发展方向八、结论摘要

python与QT联合的详细步骤记录

《python与QT联合的详细步骤记录》:本文主要介绍python与QT联合的详细步骤,文章还展示了如何在Python中调用QT的.ui文件来实现GUI界面,并介绍了多窗口的应用,文中通过代码介绍... 目录一、文章简介二、安装pyqt5三、GUI页面设计四、python的使用python文件创建pytho

QT实现TCP客户端自动连接

《QT实现TCP客户端自动连接》这篇文章主要为大家详细介绍了QT中一个TCP客户端自动连接的测试模型,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录版本 1:没有取消按钮 测试效果测试代码版本 2:有取消按钮测试效果测试代码版本 1:没有取消按钮 测试效果缺陷:无法手动停

基于Qt实现系统主题感知功能

《基于Qt实现系统主题感知功能》在现代桌面应用程序开发中,系统主题感知是一项重要的功能,它使得应用程序能够根据用户的系统主题设置(如深色模式或浅色模式)自动调整其外观,Qt作为一个跨平台的C++图形用... 目录【正文开始】一、使用效果二、系统主题感知助手类(SystemThemeHelper)三、实现细节

Qt实现文件的压缩和解压缩操作

《Qt实现文件的压缩和解压缩操作》这篇文章主要为大家详细介绍了如何使用Qt库中的QZipReader和QZipWriter实现文件的压缩和解压缩功能,文中的示例代码简洁易懂,需要的可以参考一下... 目录一、实现方式二、具体步骤1、在.pro文件中添加模块gui-private2、通过QObject方式创建

Qt QWidget实现图片旋转动画

《QtQWidget实现图片旋转动画》这篇文章主要为大家详细介绍了如何使用了Qt和QWidget实现图片旋转动画效果,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 一、效果展示二、源码分享本例程通过QGraphicsView实现svg格式图片旋转。.hpjavascript