Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Positioning widgets



  • I was wondering what's the "most accepted way" about positioning widgets and other elements on QT.

    Should I do it by code or by forms?

    This came up because I'm trying to make a Qpixmap image have its position relative to a point so if I resize the window it doesn't stay in the same place, I have searched anchoring but the examples I found uses a Qgraphicsscene which I'm not sure at all if it is what I need.

    Thanks!



  • learn the layouts, the size hints, and the size policies.



  • Im assuming you mean these
    Screenshot_5.png

    My main doubt is what is the preferred way to do it, if by code or if using the QCreator Form tab.

    These layouts are useful if I want to do it by code though so thanks !


  • Lifetime Qt Champion

    Hi,

    The prefered way is whatever fits best with you. Some like designer because they can directly see the widgets look and other prefer to do everything by code because they are used to that and can visualize the result without designer. It's more a question of taste.

    Personally I never use Designer except when there's a need to debug it or do a test for something related to it. However, I think that it's a nice tool that allow people to create their interface visually easily.



  • Got it! Thanks :)


  • Lifetime Qt Champion

    Hi
    And just to have both ways.
    I mostly do all in Designer and love the promotion feature allowing me to design with a custom widget.
    I use the dynamic property system to allow Design time customization for my custom widgets
    and the only code i write is for the dynamic parts. (loading data ) and for the parts
    that Designer do not support.

    Also, for a team, using UI files makes it easier for the non-UX developers to add a button and such
    without having to know exactly how it works as it's easy to drag a widget from left to someplace on the form/in the layout. Finding the same spot in many lines of code is not that easy.

    Also, designing complex layout using a Designer is good for leaning as you see the result at once.
    From code, you have to run to see what you got.

    That said, writing layouts in code, gives a firm understanding of how they work.

    For your case. Qt does not have anchoring as such with Widgets
    so unless one of the layouts suits the case, then manually setting the pixmap pos in resizeEvent
    is also an option.


Log in to reply