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++如何通过Qt反射机制实现数据类序列化

《C++如何通过Qt反射机制实现数据类序列化》在C++工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作,所以本文就来聊聊C++如何通过Qt反射机制实现数据类序列化吧... 目录设计预期设计思路代码实现使用方法在 C++ 工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作。由于数据类

Qt中QGroupBox控件的实现

《Qt中QGroupBox控件的实现》QGroupBox是Qt框架中一个非常有用的控件,它主要用于组织和管理一组相关的控件,本文主要介绍了Qt中QGroupBox控件的实现,具有一定的参考价值,感兴趣... 目录引言一、基本属性二、常用方法2.1 构造函数 2.2 设置标题2.3 设置复选框模式2.4 是否

QT进行CSV文件初始化与读写操作

《QT进行CSV文件初始化与读写操作》这篇文章主要为大家详细介绍了在QT环境中如何进行CSV文件的初始化、写入和读取操作,本文为大家整理了相关的操作的多种方法,希望对大家有所帮助... 目录前言一、CSV文件初始化二、CSV写入三、CSV读取四、QT 逐行读取csv文件五、Qt如何将数据保存成CSV文件前言

Qt中QUndoView控件的具体使用

《Qt中QUndoView控件的具体使用》QUndoView是Qt框架中用于可视化显示QUndoStack内容的控件,本文主要介绍了Qt中QUndoView控件的具体使用,具有一定的参考价值,感兴趣的... 目录引言一、QUndoView 的用途二、工作原理三、 如何与 QUnDOStack 配合使用四、自

Qt spdlog日志模块的使用详解

《Qtspdlog日志模块的使用详解》在Qt应用程序开发中,良好的日志系统至关重要,本文将介绍如何使用spdlog1.5.0创建满足以下要求的日志系统,感兴趣的朋友一起看看吧... 目录版本摘要例子logmanager.cpp文件main.cpp文件版本spdlog版本:1.5.0采用1.5.0版本主要

如何高效移除C++关联容器中的元素

《如何高效移除C++关联容器中的元素》关联容器和顺序容器有着很大不同,关联容器中的元素是按照关键字来保存和访问的,而顺序容器中的元素是按它们在容器中的位置来顺序保存和访问的,本文介绍了如何高效移除C+... 目录一、简介二、移除给定位置的元素三、移除与特定键值等价的元素四、移除满足特android定条件的元

C++从序列容器中删除元素的四种方法

《C++从序列容器中删除元素的四种方法》删除元素的方法在序列容器和关联容器之间是非常不同的,在序列容器中,vector和string是最常用的,但这里也会介绍deque和list以供全面了解,尽管在一... 目录一、简介二、移除给定位置的元素三、移除与某个值相等的元素3.1、序列容器vector、deque

C++常见容器获取头元素的方法大全

《C++常见容器获取头元素的方法大全》在C++编程中,容器是存储和管理数据集合的重要工具,不同的容器提供了不同的接口来访问和操作其中的元素,获取容器的头元素(即第一个元素)是常见的操作之一,本文将详细... 目录一、std::vector二、std::list三、std::deque四、std::forwa

Spring MVC使用视图解析的问题解读

《SpringMVC使用视图解析的问题解读》:本文主要介绍SpringMVC使用视图解析的问题解读,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Spring MVC使用视图解析1. 会使用视图解析的情况2. 不会使用视图解析的情况总结Spring MVC使用视图

Qt 中 isHidden 和 isVisible 的区别与使用小结

《Qt中isHidden和isVisible的区别与使用小结》Qt中的isHidden()和isVisible()方法都用于查询组件显示或隐藏状态,然而,它们有很大的区别,了解它们对于正确操... 目录1. 基础概念2. 区别清见3. 实际案例4. 注意事项5. 总结1. 基础概念Qt 中的 isHidd