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

Responsive Design - Change between many buttons / one button with menu depending on space available



  • Hi,

    I have a UI where there are many QToolButtons in a HBoxLayout.
    Now if the monitor size is too small I want to group them in fewer QToolButtons that have a menu instead of individual buttons.

    Is there some default mechanism in Qt implemented for this kind of task or do I have to implement it myself?
    And if not, is there an example on how to implement this somewhere?

    Since it is a common problem I guess somebody has solved it before.

    Thanks


  • Lifetime Qt Champion

    Hi
    well qtoolbar shows maker and can expand the toolbar.
    alt text
    It will not make a menu out of it. That is something you have to implement yourself. :)
    And a layout will not by any means do such thing.



  • @mjii thanks for the hint with the toolbar. However I prefer the menu and therefore will implement it myself.
    There I have one question:
    How is it possible to find out if there is enough space for a widget or if it gets vignetted/cut off?


  • Lifetime Qt Champion

    hi

    -How is it possible to find out if there is enough space for a widget or if it gets vignetted/cut off?

    Well you can use
    http://doc.qt.io/qt-5/qrect.html#contains-1
    with proper as true.
    for the widget and its parents's rect()
    (i assume parent adjusts to windows size)


Log in to reply