开发者

Are there any useful tools for diagnosing Qt layout and spacing problems?

开发者 https://www.devze.com 2023-02-19 06:00 出处:网络
See also related question: How do you debug Qt layout problems 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

See also related question: How do you debug Qt layout problems

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.

However, I keep thinking that there must be a better way. Looking at tools such as Firefox's web d开发者_如何学JAVAeveloper 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?

UPDATE 5 May 2016

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

Another tool: https://github.com/robertknight/Qt-Inspector


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

EDIT: I've also found a useful technique hidden away in the documentation of QLayout::itemAt() which shows how to iterate through the QLayoutItems in a layout and draw their rectangles


Could you use a QHoverEvent to add a dark border or a popup with an id every time you hover over an element?


What you are looking for is basically a tool that analyzes the QObject or rather QWidget hierarchy and adds annotations. This is exactly what GammaRay is about. It is GPL licensed and therefore freely available. You can get further infos on the GammaRay project page. I've used it several times, and it works as expected.


Late, but QObject::dumpObjectTree() helped me solve my issues.

Dumps a tree of children to the debug output.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号