QML的Rectangle组件,描绘一个矩形,一个可视化的对象。

外加设置属性来达到我们想要的效果。常用的有矩形的颜色,边框颜色,圆角等设置。

 Rectangle{
x://这里的坐标是相对于它的父窗口,也就是Window
y:
width: ;
height: ;//一定要指定出大小才能显示
visible: true
antialiasing: true;//抗锯齿,默认就是开启的
border.width: ;
border.color: "red";//边框的一些属性
color: "blue"//内部的颜色
radius: //圆角半径
gradient: Gradient{//颜色渐变
GradientStop { position: 0.0; color: "lightsteelblue" }
GradientStop { position: 1.0; color: "blue" }
}
clip:true//这一属性设置表示如果他的子类超出了范围,那么就剪切掉,不让他显示和起作用
Rectangle{
id:son
x:; //基于父窗口的位置
y:;
width: ;
height: ;
color: "gray";
}
}

 Rectangle {
color: "blue"
width: ; height:
Rectangle {
color: "green"
width: ; height:
}
Rectangle {
color: "red"
x: ; y: ; width: ; height:
scale: 1.5 //放大1.5倍
transformOrigin: "TopLeft" //改变元素的原点位置
}
}

  Row {
Rectangle {
width: ; height:
color: "blue"
transform: Translate { y: }//下移
}
Rectangle {
width: ; height:
color: "red"
transform: Translate { y: - }//上移
}
}
   Rectangle {
width: ; height:
color: "red"
PropertyAnimation on x { to: ; duration: ; loops: Animation.Infinite } //从(0,0)坐标移动到(50。50),
PropertyAnimation on y { to: ; duration: ; loops: Animation.Infinite }//1000表示一秒时间, duration 越大移动越慢
} Rectangle {
width: ; height:
color: "red"
PropertyAnimation on x { to: ; duration: ; easing.type: Easing.OutBounce }
PropertyAnimation on y { to: ; duration: ; easing.type: Easing.OutBounce }//移动到50,50 ,OutBounce 动画效果
} Rectangle {
width: ; height: ; anchors.centerIn: parent
color: "red"
RotationAnimation on rotation { to: ; direction: RotationAnimation.Clockwise } //旋转90°
} Rectangle {
width: ; height:
ColorAnimation on color { from: "red"; to: "yellow"; duration: } //在1s时间内 颜色变化
}
  // Rectangle 跟随鼠标移动 写法一
Item {
width: ; height: Rectangle {
id: rect
width: ; height:
color: "red" Behavior on x { PropertyAnimation { duration: } }
Behavior on y { PropertyAnimation { duration: } }
} MouseArea {
anchors.fill: parent
onClicked: { rect.x = mouse.x; rect.y = mouse.y }
}
} // Rectangle 跟随鼠标移动 写法二
Rectangle {
id: rect
width: ; height:
color: "red" PropertyAnimation {
id: animation
target: rect
properties: "x,y"
duration:
} MouseArea {
anchors.fill: parent
onClicked: {
animation.to = ;
animation.running = true;
}
}
}
// Rectangle 跟随鼠标移动 写法三
Rectangle {
id: rect
width: ; height:
color: "red" MouseArea {
anchors.fill: parent
onClicked: rect.state = "moved"
} states: State {
name: "moved"
PropertyChanges { target: rect; x: ; y: }
} transitions: Transition {
PropertyAnimation { properties: "x,y"; duration: }
}
}
 // 自由落体动画效果
Rectangle {
id: rect
width: ; height: Image {
id: img
source: "colors.png"
anchors.horizontalCenter: parent.horizontalCenter
y: SequentialAnimation on y {
loops: Animation.Infinite
NumberAnimation { to: rect.height - img.height;
easing.type: Easing.OutBounce; duration: }
PauseAnimation { duration: }
NumberAnimation { to: ; easing.type: Easing.OutQuad;
duration: }
}
}
}

QML::Rectangle组件的更多相关文章

  1. 从头学Qt Quick(3)-- 用QML写一个简单的颜色选择器

    先看一下效果图: 实现功能:点击不同的色块可以改变文字的颜色. 实现步骤: 一.创建一个默认的Qt Quick工程: 二.添加文件Cell.qml 这一步主要是为了实现一个自定义的组件,这个组件就是我 ...

  2. QML Object Attributes QML对象属性

    QML Object Attributes Every QML object type has a defined set of attributes. Each instance of an obj ...

  3. qml demo分析(samegame-拼图游戏)

    一.效果展示 相信大家都玩儿过连连看游戏,而且此款游戏也是闲时一款打发时间的趣事,那么接下来我将分析一款类似的游戏,完全使用qml编写界面,复杂逻辑使用js完成.由于此游戏包含4种游戏模式,因此本篇文 ...

  4. OpenLayers学习笔记(二)— QML与HTML通信之画图

    作者: 狐狸家的鱼 Github: 八至 本文链接:QML与 HTML通信—实现QML中点击功能按钮在地图上画图 一.HTML-map var drarGraphic; var drawType;fu ...

  5. QML与C++混合编程详解(转)

    原文转自:http://blog.csdn.net/ieearth/article/details/42243553 原文转自:https://www.cnblogs.com/findumars/p/ ...

  6. QML与C++混合编程详解

    1.QML与C++为什么要混合编程 QML与C++为什么要混合编程,简单来说,就是使用QML高效便捷地构建UI,而C++则用来实现业务逻辑和复杂算法,下面介绍了两者间交互的方法与技巧. 2.QML访问 ...

  7. qt quick中qml编程语言

    Qt QML 入门 — 使用C++定义QML类型 发表于 2013 年 3 月 11 日   注册C++类 注册可实例化的类型 注册不实例化的QML类型 附带属性 注册C++类 注册可实例化的类型 如 ...

  8. QML 语言基础

    在<Qt Quick 简单介绍>中我们提到 QML 语法和 Json 相似,请參考<Qt on Android: http下载与Json解析>查看 Json 语法.当然这里我们 ...

  9. QtQuick多页面切换、多页面切换动画、多个qml文件数据交互

    一.QtQuick多页面切换方法 (1)“隐藏法” 前一个视图visible设为false或者透明度opacity设为0,相当于“隐藏”了,实际还存在: 要显示的视图visible设为true或者透明 ...

随机推荐

  1. 每日一题LeetCode 8. 字符串转换整数 (atoi)

    问题描述 请你来实现一个 atoi 函数,使其能将字符串转换成整数. 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止. 当我们寻找到的第一个非空字符为正或者负号时,则将 ...

  2. TypeScript 装饰器的执行原理

    装饰器本质上提供了对被装饰对象 Property​ Descriptor 的操作,在运行时被调用. 因为对于同一对象来说,可同时运用多个装饰器,然后装饰器中又可对被装饰对象进行任意的修改甚至是替换掉实 ...

  3. windows 使用 curl 命令

    什么是curl命令? curl是利用URL语法在命令行方式下工作的开源文件传输工具.它被广泛应用在Unix.多种Linux发行版中,并且有DOS和Win32.Win64下的移植版本. 如何在windo ...

  4. .net Core 使用AutoMapper

    在我们的项目中慢慢的要把数据库的实体模型和视图模型进行分离,防止被人拿到我们表字段.在学校的时候自己只是有将很多数据库模型,写成一个视图模型返回到前台. 首先我们把这两个包引入项目中去. 然后我们创建 ...

  5. USB免驱RFID读写器编程解析之一:智能卡篇

    随着RFID应用的普及,越来越多的软件工程师需要使用RFID读写器编程来实现自己的需求.为了使软件工程师更快的了解RFID读写器的使 用,本文选择一款市面上常用的USB免驱RFID读写器SDT-HA来 ...

  6. Java-环境搭建(Mac版)

    对于开发人员来说,电脑的性能很重要,所以换了Mac后需要重新配置开发环境,网上对Windows系统的Java环境配置有很多,所以,这里就不多介绍.现在记录一下在Mac电脑上的Java环境配置. 众所周 ...

  7. Android Studio如何配置CURL指令一键打包apk上传至蒲公英

    Android Studio如何配置CURL指令一键打包apk上传至蒲公英 第一步:在所需要打包的模块build.gradle文件中加入如下代码: android{ buildTypes { //配置 ...

  8. Docker 镜像介绍和命令

    目录 是什么 UnionFS(联合文件系统) Docker镜像加载原理 分层的镜像 为什么 Docker 镜像要采用这种分层结构呢 特点 Docker镜像commit操作补充 案例演示 1.从Hub上 ...

  9. go语言设计模式之Command

    package main import ( "fmt" ) type Command interface { Execute() } type ConsoleOutput stru ...

  10. 爬取沪深a股数据

    首先从东方财富网获取股票代码 再从网易财经下载股票历史数据 import requests import random from bs4 import BeautifulSoup as bs impo ...