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 ...
随机推荐
- IO 模型 IO 多路复用
IO 模型 IO 多路复用 IO多路复用:模型(解决问题的方案) 同步:一个任务提交以后,等待任务执行结束,才能继续下一个任务 异步:不需要等待任务执行结束, 阻塞:IO阻塞,程序卡住了 非阻塞:不阻 ...
- Python距离放弃拉近的day03
新的一天,依旧是内容补充,补充了数学没有的运算符,in和not in,就是判断in前面的东西是不是在后面的数据中,然后新课讲了平常最常用的字符串的方法,引号的里面全部都是字符串,在其中就会又如何判断这 ...
- Django-CRM项目学习(五)-stark的action以及多级筛选功能
1.stark的组件之action(自定制函数多选功能效果) 1.1 admin效果 1.2 多选效果前端和后端进行的操作 1.2.1 前端发过来的参数是?号后各个参数用&来拼接 1.2.2 ...
- 转://ORA-00603,ORA-27501,ORA-27300,ORA-27301,ORA-27302故障案例一则
背景介绍: 这是一套windows的rac系统.数据库后台日志报ORA-00474:SMON process terminated with error.接着报ORA-00603,ORA-27501, ...
- Windows10下安装Oracle 11g 64位的详细步骤
直接附上我整理后的Word版<Windows10下安装Oracle 11g 64位的详细步骤>下载地址,提取码:9vak. 参考文献: 1.Win10 64位系统下安装Oracle11g详 ...
- Linux内核入门到放弃-页缓存和块缓存-《深入Linux内核架构》笔记
内核为块设备提供了两种通用的缓存方案. 页缓存(page cache) 块缓存(buffer cache) 页缓存的结构 在页缓存中搜索一页所花费的时间必须最小化,以确保缓存失效的代价尽可能低廉,因为 ...
- 固件远程更新之STARTUPE2原语(fpga控制flash)
作者:九章子 来源:CSDN 原文:https://blog.csdn.net/jiuzhangzi/article/details/79471365 有的项目需要远程更新固件,更新完成后断电.重启即 ...
- 控制结构(4): 局部化(localization)
// 上一篇:状态机(state machine) // 下一篇:必经之地(using) 基于语言提供的基本控制结构,更好地组织和表达程序,需要良好的控制结构. 前情回顾 上一次,我们说到状态机结构( ...
- PHP之环境配置
我们的网站一般从开发到上线,整个过程会经历三个过程,本地开发->测试服测试->线上生产环境 对于不同环境下的配置也会不同,对于区分不同的环境是十分重要的. 1 域名判断法 使用的较多 ...
- Crypto加密解密
crypto 模块提供了加密功能,包含对 OpenSSL 的哈希.HMAC.加密.解密.签名.以及验证功能的一整套封装.我们这里讲crypto AES算法加密 一.使用步骤 1.引入Crypto 1. ...