qml : qml控件自适应;
import QtQuick 2.4
Item {
property var targetItem: parent
property bool fixedAspectRatio: true // Else zoom from width and height
property bool accordingToX: true // Else according to center
property var targetItemGeometry
property var childrenItemGeometry
property bool isBegin: false
function begin() {
targetItemGeometry = new Object;
targetItemGeometry["width"] = targetItem.width;
targetItemGeometry["height"] = targetItem.height;
var children = targetItem.children;
var data = new Array;
for(var index = 1; index < children.length; index++)
{
var currentItem = children[index];
var buf = new Object;
buf["item"] = currentItem;
buf["x"] = currentItem.x;
buf["y"] = currentItem.y;
buf["centerX"] = currentItem.x + (currentItem.width / 2);
buf["centerY"] = currentItem.y + (currentItem.height / 2);
buf["width"] = currentItem.width;
buf["height"] = currentItem.height;
data.push(buf);
}
childrenItemGeometry = data;
isBegin = true;
}
function resize() {
if(isBegin)
{
var horizontalRatio, verticalRatio;
horizontalRatio = targetItem.width / targetItemGeometry["width"];
verticalRatio = targetItem.height / targetItemGeometry["height"];
for(var index = 0; index < childrenItemGeometry.length; index++)
{
if(fixedAspectRatio)
{
if(horizontalRatio > verticalRatio)
{
childrenItemGeometry[index]["item"].width = childrenItemGeometry[index]["width"] * verticalRatio;
childrenItemGeometry[index]["item"].height = childrenItemGeometry[index]["height"] * verticalRatio;
}
else
{
childrenItemGeometry[index]["item"].width = childrenItemGeometry[index]["width"] * horizontalRatio;
childrenItemGeometry[index]["item"].height = childrenItemGeometry[index]["height"] * horizontalRatio;
}
}
else
{
childrenItemGeometry[index]["item"].width = childrenItemGeometry[index]["width"] * horizontalRatio;
childrenItemGeometry[index]["item"].height = childrenItemGeometry[index]["height"] * verticalRatio;
}
if(accordingToX)
{
childrenItemGeometry[index]["item"].x = childrenItemGeometry[index]["x"] * horizontalRatio;
childrenItemGeometry[index]["item"].y = childrenItemGeometry[index]["y"] * verticalRatio;
}
else
{
childrenItemGeometry[index]["item"].x = childrenItemGeometry[index]["centerX"] * horizontalRatio - (childrenItemGeometry[index]["item"].width / 2);
childrenItemGeometry[index]["item"].y = childrenItemGeometry[index]["centerY"] * verticalRatio - (childrenItemGeometry[index]["item"].height / 2);
}
}
}
}
Component.onCompleted: {
begin();
}
Component {
id: connections
Connections {
target: targetItem
onWidthChanged: {
resize();
}
onHeightChanged:
{
resize();
}
}
}
Loader {
Component.onCompleted: {
sourceComponent = connections;
}
}
}
qml : qml控件自适应;的更多相关文章
- 【IOS界面布局】横竖屏切换和控件自适应(推荐)
[IOS界面布局]横竖屏切换和控件自适应(推荐) 分类: [MAC/IOS下开发]2013-11-06 15:14 8798人阅读 评论(0) 收藏 举报 横竖屏切换 自适应 第一种:通过人为的办法改 ...
- C# WinForm窗体及其控件自适应各种屏幕分辨率
C# WinForm窗体及其控件自适应各种屏幕分辨率 一.说明 我们自己编写程序的界面,会遇到各种屏幕分辨率,只有自适应才能显的美观.实际上,做到这点也很简单,就是首先记录窗体和它上面控件的初始位置 ...
- C# Winform窗体和控件自适应大小
1.在项目中创建类AutoSizeForm AutoSizeForm.cs文件代码: using System; using System.Collections.Generic; using Sys ...
- QML常用控件
这里的控件是显示的元素 1.Item:一切的基类 Item { Image { source: "tile.png" } Image { x: width: height: sou ...
- Winfon 页签切换及窗体控件自适应
由于公司的业务调整,最近不仅开发bs,还有不熟悉的cs,人手也不足,项目还多,对于cs来说,算是小白,虽然是一个人,也是硬着头皮写,拖拽控件,自定义控件.一个项目下来,对cs有了很深的认识,这里好好感 ...
- Winform窗体控件自适应大小
自己写的winform窗体自适应大小代码,代码比较独立,很适合贴来贴去不会对原有程序造成影响,可以直接继承此类或者把代码复制到自己的代码里面直接使用 借鉴了网上的一些资料,最后采用重写WndProc方 ...
- C#(winform)实现不同DPI控件自适应1
1. PicBox控件 顺便一提关键字:stretch [stretʃ] vt. 伸展,张开 //控制pictureBox图片的显示格式 this.picClose.BackgroundImageLa ...
- MFC的停靠窗口中插入对话框,在对话框中添加控件并做控件自适应
单文档程序添加了停靠窗口后,可能会在停靠窗口中添加一些控件.在这里我的做法是在对话框上添加控件并布局,然后将这个对话框插入到停靠窗口中. 步骤 1.插入对话框,在对话框中放入控件(我的为树形控件),并 ...
- 【2017-12-06】winfrom 窗体自启最大化,控件自适应
先将窗体windowstate属性设置为Maximized public partial class Form1 : Form { public Form1() { InitializeCompone ...
随机推荐
- C#比较两个由基本数据类型构成的object类型
/// <summary> /// 比较查询条件 /// </summary> public class ModelExtensions { /// <summary&g ...
- Java 位运算符和 int 类型的实现
Java 位运算符和 int 类型的实现 其他运算符 # 算术运算符 +.-.*./.++i.i++.--i.i-- # 关系运算符 ==.!=.>.<.>=.<= # 逻辑运 ...
- jenkins安装详细教程
一.jenkins简介 jenkins是一个开源的软件项目,是基于java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能. 1.持续的软件版本 ...
- 【Teradata UDF】中文按字符查找chs_instr
一.场景描述 数据库为ASCII编码单字节存储,在查询中文时可能会出现错误结果.例如查询like“房”字,会查询出不含“房”,含“朔科”的结果. select * from Tablename01 w ...
- sbt安裝與配置
官方下載地址:https://www.scala-sbt.org/download.html?spm=a2c4e.11153940.blogcont238365.9.42d147e0iF8dhv 解压 ...
- HBase实践案例:知乎 AI 用户模型服务性能优化实践
用户模型简介 知乎 AI 用户模型服务于知乎两亿多用户,主要为首页.推荐.广告.知识服务.想法.关注页等业务场景提供数据和服务, 例如首页个性化 Feed 的召回和排序.相关回答等用到的用户长期兴趣特 ...
- Operation category READ is not supported in state standby
Namenode 开启HA之后,由于zookeeper异常,出现脑裂现象 执行 $./hdfs haadmin -getServiceState nn1 ...
- 基于SVM的鸢尾花数据集分类实现[使用Matlab]
iris数据集的中文名是安德森鸢尾花卉数据集,英文全称是Anderson’s Iris data set.iris包含150个样本,对应数据集的每行数据.每行数据包含每个样本的四个特征和样本的类别信息 ...
- 前端学习-基础部分-css(一)
开始今日份整理 1.CSS的导入方式 CSS的导入方式主要是有内联模式,行内模式,外部样式表 1.1 内联模式 内联模式:直接在<head>中直接写css,例如 p{ color:rgb( ...
- Django模板语言(Template)
1.变量 变量相关用 { { } } 逻辑相关用{% %} 2.Filter过滤器 (1)default 如果一个变量是false或者为空,使用给定的默认值. 否则,使用变量的值. {{ va ...