Adding widget to evenly spaced grid
-
I need to dynamically add multiple widgets of the same type to a 5x10 grid. The vertical and horizontal distance between each widget should be constant, regardless of how many widgets are currently in the grid. As widgets are added, they will fill a row (left to right) before starting a new row.
Currently, this doesn't seem possible with QGridLayout as the distance between widgets adjusts. Is my best bet to just use a QFrame and handle the positioning of the widgets myself, which I think will be fairly trivial?
-
Add a spacer right and bottom of the grid layout so it shrinks when there are no widgets.
-
@EaccB said in Adding widget to evenly spaced grid:
How would I control the spacing between each widget?
Maybe by taking a look at the documentation? https://doc.qt.io/qt-5/qgridlayout.html#horizontalSpacing-prop
-
I've added a vertical and horizontal spacer to the bottom and right side of the grid. As I add widgets, how can I ensure that a widget doesn't overlap a spacer? I.e, there should always be a spacer at the bottom and right - added widgets should be to the top-left of the spacers.
-
I don't understand what you mean - when you add a widget to your grid how should it overlap a spacer which is outside of the grid?
-
@EaccB You can add spacers in another layout there too.