当前位置:网站首页>QML使用Layout布局时出现大量<Unknown File>: QML QQuickLayoutAttached: Binding loop detected for property循环绑定警告
QML使用Layout布局时出现大量<Unknown File>: QML QQuickLayoutAttached: Binding loop detected for property循环绑定警告
2022-07-28 02:23:00 【难搞哦~】
首先QML实现布局有三种工具方法:
(1)锚:anchors
(2)布局管理器:RowLayout、ColumnLayout、GridLayout
(3)定位器:Row、Column、Grid、Flow、Position、Repeater
在实现子控件随窗口大小改变而跟随变化时,经常使用布局管理器RowLayout、ColumnLayout、GridLayout,这三种布局管理器与那三种定位器Row、Column、Grid是有区别的,布局管理器大小变化时可以让子控件也跟随变化,可以限定最小尺寸、最大尺寸、最佳尺寸、自适应宽高,但是定位器虽然也可以通过宽度和高度与父控件的关系实现跟随变化,但是不能限定最小、最大、最佳尺寸、也不能自适应宽高,要实现相同的效果肯定不如直接使用布局管理器方便。
本文主要讲解在嵌套使用布局管理器,经常出现宽、高的循环绑定警告提示,程序加载很久才能进入画面的问题:

以上代码出现如下报错:

原因:
以上代码所示,ColumnLayout的大小填充为父亲的全部,ColumnLayout里面嵌套了RowLayout,而且给RowLayout设置了自适应宽度和32的高度,但是由于布局管理器内的布局管理器的实际宽高由其子控件的宽高决定的,所以对RowLayout设置的自适应宽度和32的高度其实是无效的,RowLayout的实际宽高由其子控件的宽高决定,但是代码中其子控件Rectangle的最小宽度设置为父亲宽度的30%,由此产生互相依赖的死循环:
RowLayout的宽高由其两个子控件Rectangle的总宽高决定,而两个子控件Rectangle的宽度又由父亲RowLayout的宽度决定。
解决方法:
(1)最优解决方法:
嵌套使用布局管理器时,应使用一个宽度高度可设置的控件(Item或Rectangle)作为隔离层:

(2)其他解决方法:避免在直接嵌套的布局管理器内设置其子控件的宽高受父亲的影响,可以设置跟随爷爷级以上,但往往我们就是需要跟随父亲的效果,所以这种方法不太好。
边栏推荐
- Opengauss Developer Day 2022 sincerely invites you to visit the "database kernel SQL Engine sub forum" of Yunhe enmo
- Day 19 of leetcode
- Redis群集
- 嵌入式开发:提示和技巧——用C进行防御性编程的最佳实践
- Design of the multi live architecture in different places of the king glory mall
- exness:日本物价上涨收入下降,英镑/日元突破 165
- tfx airflow 使用体验
- Note that these regions cannot take the NPDP exam in July
- 满满干货赶紧进来!!!轻松掌握C语言中的函数
- Promise object
猜你喜欢

Interview experience: first tier cities move bricks and face software testing posts. 5000 is enough

别再用 offset 和 limit 分页了,性能太差!

写英文IEEE论文的技巧

Development and design logic of rtsp/onvif protocol easynvr video platform one click upgrade scheme

Scheme sharing | experts gather to jointly explore accent AI speech recognition

会议OA项目之我的审批&&签字功能

Distributed transaction Senta (I)

Day 8 of DL

exness:日本物价上涨收入下降,英镑/日元突破 165

Opengauss Developer Day 2022 sincerely invites you to visit the "database kernel SQL Engine sub forum" of Yunhe enmo
随机推荐
NPDP candidates! The exam requirements for July 31 are here!
CSDN TOP1“一个处女座的程序猿“如何通过写作成为百万粉丝博主?
Oracle basicfile lob field space recycling shrink space doubts
一次跨域问题的记录
QT专题1:实现一个简易计算器
行业洞察 | 语音识别真的超过人耳朵了吗?
微服务架构统一安全认证设计与实践
Actual case of ROS communication
蓝桥杯:第九届—“彩灯控制器”
MySQL索引学习
Using pytorch's tensorboard visual deep learning indicators | pytorch series (25)
关于权重衰退和丢弃法
Unexpected harvest of epic distributed resources, from basic to advanced are full of dry goods, big guys are strong!
"29 years old, general function test, how do I get five offers in a week?"
Note that these regions cannot take the NPDP exam in July
QT topic 1: implementing a simple calculator
Docker advanced -redis cluster configuration in docker container
[stream] basic knowledge of stream
综合 案例
What kind of job is social phobia suitable for? Can you do we media?