是否有诊断Qt布局和间距问题的有用工具? [英] Are there any useful tools for diagnosing Qt layout and spacing problems?

查看:80
本文介绍了是否有诊断Qt布局和间距问题的有用工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另请参阅相关问题: 您如何调试Qt布局问题

我正在尝试布局一些复杂的小部件层次结构,并且遇到了一些比我预期的更紧密或更远的问题.我发现一种非常有用的技术是为样式表创建一个样式表,该样式表为层次结构中不同点的小部件提供不同背景和边框颜色的列表.我还添加了一个QFileSystemWatcher,以便在每次保存样式表时重新加载样式表,从而可以快速进行更改而无需重建.

I've got some complex widget hierarchies that I'm trying to lay out, and I run into the usual problems of things being closer together or further apart than I expect. I've found a very useful technique is to create a stylesheet with a list of different background and border colours for widgets at different points in the hierarchy. I've also added a QFileSystemWatcher to reload the stylesheet every time it's saved which allows rapid changes without needing to rebuild.

但是,我一直认为必须有更好的方法.查看诸如Firefox的Web开发人员工具栏之类的工具,这些工具会做一些事情,例如标记边框或显示控件的层次结构.是否有任何工具或库可以对Qt应用程序执行此操作?

However, I keep thinking that there must be a better way. Looking at tools such as Firefox's web developer toolbar which will do things like mark borders or show the hierarchy of controls. Are there any tools or libraries that will do this for Qt apps?

我发现诊断间距问题的最简单,最有用的方法之一是根据QLayouts转储小部件层次结构.我创建了一些示例代码,其中嵌入了有关尺寸提示,间隔项,填充和内容边距的信息: https: //gist.github.com/pjwhams/6ebc040db3ab55615eafd831e184e39c

I've found one of the easiest and most informative ways of diagnosing spacing problems is to dump the widget hierarchy in terms of the QLayouts. I've created some sample code that embeds information about size hints, spacer items, padding and content margins: https://gist.github.com/pjwhams/6ebc040db3ab55615eafd831e184e39c

另一个工具: https://github.com/robertknight/Qt-Inspector

推荐答案

我在另一个线程中遇到了一个相关的后续问题,Dmitry提出了一个很好的方法,导致了一个很好的解决方案:

I had a related follow-on question in another thread to which Dmitry came up with a great method that led to a good solution: Drawing an overlay on top of an application's window

我还在 QLayout::itemAt() ,其中显示了如何遍历布局中的QLayoutItems并绘制其矩形

这篇关于是否有诊断Qt布局和间距问题的有用工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆