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

Gridlayout resize automatically



  • Hi all,

    This maybe a quick question, I created a widget with designer, that widget has a gridlayout which can accept 4 widgets (2x2 matrix). The widgets are inserted dynamically, at the beginning is only 1 then 2,3 and the last is 4. When all of them are in the girdlayout matrix, their size are ok, but when there is only one it looks big.
    Is there a way to:

    1. Keep their size the same all the time in the gridlayout.
    2. when the first is added, I would to be displayed it a the center of the gridlayout.

    Thanks



  • If your add these widgets by

    layout->addWidget(widget, row, column, Qt::AlignCenter);
    

    Then Qt will try to keep their size as their sizeHint() and make them at the center of their cells.



  • If your add these widgets by

    layout->addWidget(widget, row, column, Qt::AlignCenter);
    

    Then Qt will try to keep their size as their sizeHint() and make them at the center of their cells.


Log in to reply