qml学习笔记(二):可视化元素基类Item详解(上半场anchors等等)
原博主博客地址:http://blog.csdn.net/qq21497936
本文章博客地址:http://blog.csdn.net/qq21497936/article/details/78516201
qml学习笔记(二):可视化元素基类Item详解(上半场anchors等等)
本学章节笔记主要详解Item元素(上半场主要涉及anchors锚),因为所有可视化的界面元素都继承于Item,熟悉Item后,不同的继承子类,有其定制的属性(从几个到几十个不等)。
《Qt实用技巧:在Qt Gui程序中嵌入qml界面(可动态覆盖整个窗口)》:
http://blog.csdn.net/qq21497936/article/details/78486552
《qml学习笔记(一):界面元素初探》:
http://blog.csdn.net/qq21497936/article/details/78498575
《qml学习笔记(三):可视化元素基类Item详解(下半场)》
http://blog.csdn.net/qq21497936/article/details/78522816
基类Item介绍
基类Item是所有可视化子类的父类,它不是可见的,但是它定义了所有通用元素通用的属性,比如x、y、width、height、anchoring和handingsuppourt。
几个Item的使用示例
Image示例
- Item{
- Rectangle{
- width:1000;
- height:1000;
- color:"black";
- Image { // Image默认的背景是透明
- source:"1.png"// 相对于.qml的路径
- }
- Image{
- x:80
- y:200
- width:100
- height:100
- source:"1.png"
- }
- Image{
- x:190
- y:400
- width:100
- height:100
- fillMode:Image.Tile
- source:"1.png"
- }
- }
- }
效果如下图:
捕捉键盘
- Item{
- focus:true
- Keys.onPressed:{
- if(event.key==Qt.Key_Left){
- console.log("moveleft");
- event.accepted=true;
- }
- }
- Keys.onReturnPressed:
- console.log("Pressedreturn");
- }
输入处理
- Rectangle{
- width:100;
- height:100
- FocusScope{
- id:focusScope
- focus:true
- TextInput{
- id:input
- focus:true
- }
- }
- }
效果如图
属性详解
activeFocus : bool [可读写][指示焦点:窗口是否获取焦点]
此属性指示元素是否具有活动焦点。如果指示是真的,这个对象是目前接收键盘输入,或是一个FocusScope为父对象的对象,目前接收键盘输入。
通常,此属性是通过设置焦点在其子元素(继承于Item)和其外围FocusScope对象获得。在下面的例子中,TextInput和FocusScope对象会有活跃的热点,而根矩形对象将不会。
activeFocusOnTab : bool [可读写][设置item是否可被tab选中,默认为false]
anchors:一组属性,提供了以元素相互关系为基准的定位方式,主要包括以下的:
anchors.top : AnchorLine [可读写][顶部边界]
- Item {
- Image {
- id: pic;
- x:100;
- y:200;
- source: "./1.png";
- }
- Text {
- id: label;
- anchors.top: pic.bottom; // 对象的顶部是与pic的底部高度相同
- text: "hello world";
- color: "black";
- font.pointSize: 14; // 大于0的值,与设备无关font.pixelSize:单位像素,依赖于设备
- }
- }
anchors.bottom : AnchorLine [可读写][底部边界]
- Item {
- Image {
- id: pic;
- x:100;
- y:200;
- source: "./1.png";
- }
- Text {
- id: label;
- anchors.bottom: pic.bottom; // 对象的顶部是与pic的底部高度相同
- text: "hello world";
- color: "black";
- font.pointSize: 14; // 大于0的值,与设备无关font.pixelSize:单位像素,依赖于设备
- }
- }
anchors.left : AnchorLine [可读写][左边界]
- Item {
- Image {
- id: pic;
- x:100;
- y:10;
- source: "./1.png";
- }
- Text {
- id: label;
- anchors.left: pic.right; // 对象的顶部是与pic的底部高度相同
- text: "hello world";
- color: "black";
- font.pointSize: 14; // 大于0的值,与设备无关font.pixelSize:单位像素,依赖于设备
- }
- }
anchors.right : AnchorLine [可读写][右边界]
- Item {
- Image {
- id: pic;
- x:100;
- y:10;
- source: "./1.png";
- }
- Text {
- id: label;
- anchors.right: pic.right; // 对象的顶部是与pic的底部高度相同
- text: "hello world";
- color: "black";
- font.pointSize: 14; //大于0的值,与设备无关font.pixelSize:单位为像素,依赖于设备
- }
- }
anchors.horizontalCenter : AnchorLine [可读写][水平中心]
- Item {
- Image {
- id: pic;
- source: "./1.png";
- }
- Text {
- id: label
- // 对象的水平中心 以 pic的水平中心 为中心
- anchors.horizontalCenter: pic.horizontalCenter;
- text: "hello world";
- color: "white";
- font.pointSize: 14; // 大于0的值,与设备无关font.pixelSize:单位像素,依赖于设备
- }
- }
anchors.verticalCenter : AnchorLine [可读写][垂直中心]
- Item {
- Image {
- id: pic;
- x:100;
- y:10;
- source: "./1.png";
- }
- Text {
- id: label;
- anchors.verticalCenter: pic.bottom; // 对象的顶部是与pic的底部高度相同
- text: "hello world";
- color: "black";
- font.pointSize: 14; //大于0的值,与设备无关font.pixelSize:单位像素,依赖于设备
- }
- }
anchors.baseline : AnchorLine AnchorLine [可读写][baseline是指的文本所在的线,如果item没有文字的话baseline就和top的位置是相同的]
- Item {
- Image {
- id: pic;
- x:40;
- y:40;
- source: "./1.png";
- }
- Text {
- id: label;
- anchors.baseline: pic.top;
- text: "hello world";
- color: "black";
- font.pointSize: 14; //大于0的值,与设备无关font.pixelSize:单位像素,依赖于设备
- }
- }
anchors.fill : Item [可读写][用本对象填充指向的对象元素]
- Item{
- Image{
- id:pic;
- x:40;
- y:40;
- source:"./1.png";
- }
- Rectangle{
- id:label;
- anchors.fill:pic; // 此时设置width和height,测试无效,直接填满pic
- color:"black";
- }
- }
anchors.centerIn : Item [可读写][用本对象的中心对准指向对象的中心,开始辐射出去,区域可大于设置指向的对象]
- Item {
- Image {
- id: pic;
- x:40;
- y:40;
- source: "./1.png";
- }
- Rectangle {
- id: label;
- width: 60;
- height: 60;
- anchors.centerIn: pic; // 以pic的中心为该对象中心进行辐射(区域可大于pic)
- color: "black";
- }
- }
anchors.margins : real [可读写][设置所有(top,bottom,left,right)边框的宽度]
- Item {
- Image {
- id: pic;
- x:40;
- y:40;
- source: "./1.png";
- }
- Rectangle {
- id: label;
- width: 60;
- height: 60;
- color: "black";
- anchors.margins: 10;
- anchors.left: pic.right;
- }
- Rectangle {
- id: label2;
- width: 60;
- height: 60;
- color: "black";
- anchors.margins: 10;
- anchors.top: pic.bottom;
- }
- }
- Item {
- Rectangle {
- id: label;
- width: 60;
- height: 60;
- color: "red";
- anchors.margins: 50;
- }
- Rectangle {
- id: label2;
- width: 60;
- height: 60;
- color: "black";
- anchors.margins: 50; // 只对本对象设置anchors边框有效
- anchors.top: label.bottom;
- }
- Rectangle {
- id: labe3;
- width: 60;
- height: 60;
- color: "red";
- anchors.margins: 50; // 只对本对象设置anchors边框有效
- anchors.top: labe2.bottom;
- }
- }
anchors.topMargin : real [可读写][设置top边框的宽度,参照margins]
anchors.bottomMargin : real [可读写][设置bottom边框的宽度,参照margins]
anchors.leftMargin : real [可读写][设置left边框的宽度,参照margins]
anchors.rightMargin : real [可读写][设置right边框的宽度,参照margins]
anchors.horizontalCenterOffset : real [可读写][设置水平中心偏移量]
- Item {
- Image {
- id: pic;
- source: "./1.png";
- }
- Rectangle {
- width: 30;
- height: 30;
- id: rect;
- color: "black";
- // 对象的水平中心 以 pic的水平中心 为中心
- anchors.horizontalCenter: pic.horizontalCenter;
- // 注意:horizomtalCenterOffset针对于horizontalCenter
- anchors.horizontalCenterOffset: 50;
- }
- }
anchors.verticalCenterOffset : real [可读写][参照设horizontalCenter,与其类似]
anchors.baselineOffset : real[可读写][参照设horizontalCenter,与其类似]
anchors.alignWhenCentered : bool [可读写][指定不使用半个像素绘制图形,当需要居中一个elements,宽度或者高度是基数,不使用半个像素绘制,对此处理解有疑问]
下章节
原博主博客地址:http://blog.csdn.net/qq21497936
本文章博客地址:http://blog.csdn.net/qq21497936/article/details/78516201
qml学习笔记(二):可视化元素基类Item详解(上半场anchors等等)的更多相关文章
- linux初级学习笔记四:Linux文件管理类命令详解!(视频序号:03_1)
本节学习的命令:cat(tac),more,less,head,tail,cut,sort,uniq,wc,tr 本节学习的技能:目录管理 文件管理 日期时间 查看文本 分屏显示 文本处理 文件管理命 ...
- moviepy音视频剪辑:视频剪辑基类VideoClip详解
☞ ░ 前往老猿Python博文目录 ░ 一.概述 在<moviepy音视频剪辑:moviepy中的剪辑基类Clip详解>和<moviepy音视频剪辑:moviepy中的剪辑基类Cl ...
- Ext.Net学习笔记22:Ext.Net Tree 用法详解
Ext.Net学习笔记22:Ext.Net Tree 用法详解 上面的图片是一个简单的树,使用Ext.Net来创建这样的树结构非常简单,代码如下: <ext:TreePanel runat=&q ...
- Ext.Net学习笔记23:Ext.Net TabPanel用法详解
Ext.Net学习笔记23:Ext.Net TabPanel用法详解 上面的图片中给出了TabPanel的一个效果图,我们来看一下代码: <ext:TabPanel runat="se ...
- web前端学习(三)css学习笔记部分(4)-- CSS选择器详解
4. 元素选择器详解 4.1 元素选择器 4.2 选择器分组 用英文逗号","相连,使用相同的样式表 使用通配符对所有元素进行通用设定. 4.3 类选择器详解 4.3.1. ...
- moviepy音视频剪辑:moviepy中的剪辑基类Clip详解
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt+moviepy音视频剪辑实战 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 一. ...
- 枚举基类Enum详解
本文主要是对枚举类型的基类Enum类做一个介绍: 首先,Enum类位于java.lang包下,根据类的介绍可以发现,Enum类是Java中所有枚举类的父类,将枚举作为一个set或者Map的keys来使 ...
- linux初级学习笔记六:linux用户及权限详解!(视频序号:03_4)
本节学习的命令:/etc/passwd,/etc/shadow,/etc/group文件详解 本节学习的技能: 安全上下文 文件与目录的权限管理 影子命令 用户,用户组类别详解 /etc/passwd ...
- [ kvm ] 学习笔记 6:virsh 命令及功能详解
1. 虚拟机管理操作 attach-device 从XML文件附加设备 attach-disk 附加磁盘设备 attach-interface 连接网络接口 autostart 自动启动一个域 blk ...
随机推荐
- 多字节(一般指GBK) utf8 Unicode 编码互转
// c:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\WinNls.h #define CP_ACP 0 // default to ANS ...
- 关于js的面向对象设计
function Person( name, age ){ this.name = name; this.age = age; this.sleep = function(){ alert( this ...
- mouseover&mouseout和mouseenter&mouseleave
mouseenter&mouseleave: 进入被选元素触发,进入被选元素的子元素不会重复触发. mouseover&mouseout: 进入被选元素触发,从被选元素进入其子元素会再 ...
- DNS隧道通信的检测
DNS隧道通信的检测 DNS 隧道通信 DNS 隧道通信是C&C常用的通信方式,一般常用的编码方式Base64,Binary编码,NetBios编码等,Hex编码等.且请求的Type一般都是t ...
- iconfont阿里爸爸做的开源图库
iconfont 三种使用姿势 1.unicode格式 优点 兼容性最好,支持ie6+ 支持按字体的方式去动态调整图标大小,颜色等等 缺点 不支持多色图标 在不同的设备浏览器字体的渲染会略有差别,在不 ...
- 2.void 0 与 不可靠的undefined
在 ES5 之前,全局的 undefined 也是可以被修改的,而在 ES5 中,该标识符被设计为了只读标识符, 假如你现在的浏览器不是太老,你可以在控制台中输入以下语句测试一下: undefined ...
- 【BZOJ3958】[WF2011]Mummy Madness 二分+扫描线+线段树
[BZOJ3958][WF2011]Mummy Madness Description 在2011年ACM-ICPC World Finals上的一次游览中,你碰到了一个埃及古墓. 不幸的是,你打开了 ...
- 【Android】 ImageView.ScaleType设置图解
ImageView的Scaletype决定了图片在View上显示时的样子,如进行何种比例的缩放,及显示图片的整体还是部分,等等. 设置的方式包括: 1. 在layout xml中定义android:s ...
- Mac - iPhone屏幕录制
1. Mac电脑屏幕录制 1.1 文件->新建屏幕录制 1.2 点击红色按钮 1.3 截取需要录制的屏幕部分,点击开始录制 1.4 点击工具栏的停止按钮,停止录制 1.5 然后会 ...
- 宝塔面板快速开启https服务
最近在做小程序开发,急需要一个https的域名,首先我的域名是阿里云的,服务器是腾讯云的,操作都一样: 无论阿里云还是腾讯云,配置SSL是针对服务器的,所以首先是要去申请 腾讯/阿里云服务器的SSL( ...