[HN Gopher] Rectangle{} debugging in QML - like printf(), but fo...
___________________________________________________________________
Rectangle{} debugging in QML - like printf(), but for QT
Author : jandeboevrie
Score : 16 points
Date : 2021-09-12 16:46 UTC (2 days ago)
(HTM) web link (raymii.org)
(TXT) w3m dump (raymii.org)
| milianw wrote:
| You should look into GammaRay which allows you to such debugging
| without having to change your code. You can literally just pick
| the element on the screen. See: https://github.com/KDAB/GammaRay/
| joezydeco wrote:
| Why wouldn't you figure out the anchors/margins/separation during
| development? Why wait for debugging to do this?
|
| Qt Creator still has the form designer (NOT the debugger as
| mentioned in the post) that can be brought up on any component.
| It's not optimal either, but it's better than modifying item
| scalars by hand.
| jandeboevrie wrote:
| This was during development, also stated in the article.
|
| The forms designer does not work if you use qrc:/ includes or
| inline javascript, plus it generates ugly code (and uses hard x
| / y positions instead of anchors).
| pestophagous wrote:
| Indeed, it's all rectangles, all the way down. (For the most
| part.)
|
| I implement a lot of QML (with C++ viewModels to back it).
|
| My UI designer actually issued a challenge to me, to see if I
| could get "Debug Rectangles" to toggle on-and-off without a
| rebuild. I'm so grateful for that challenge, because once the
| seed of the idea was planted, my thirst for this "nice-to-have"
| feature grew until I couldn't NOT solve it.
|
| I now have:
|
| ``` DebugRectangle{} ```
|
| https://github.com/219-design/qt-qml-project-template-with-c...
|
| ... which I place inside any item that needs a highlight. I then
| _leave_ _this_ _code_ _in_ _place_ (nothing to comment-in
| /comment-out).
|
| I hijack an environment variable for the toggle. The icing on the
| cake was seeing that this works both when running a compiled
| binary executable ("my Qt/QML app binary") and when viewing my
| QML with just qmlscene. https://github.com/219-design/qt-qml-
| project-template-with-c...
| jandeboevrie wrote:
| This is so cool! I think this is going to be very useful for
| me. How did you find the magic env variable?
| yellow_lead wrote:
| If it's a non-release build that seems fine, but do you have a
| way to disable this in release builds? Even if the object
| doesn't show, since QML may be loaded dynamically, having these
| scattered around could slow your app.
| xgulfie wrote:
| A mention of QDebug() is probably warranted here as well, since
| qml element behavior can be implemented in c++
___________________________________________________________________
(page generated 2021-09-14 23:03 UTC)