When I use QGridLayout, it's have 2*12 buttons, i want to setting the spacing automatically.
-
Eeach button size is fixed to 80*50
the QGridLayout's size is 1024 * 160
I want the QGridLayout to automatically spacing the
buttons. once I changed the button's size,
the layout is changed. -
I not sure wath you want, if you want to line up your buttons in two
rows each containing 12 buttons, than I would use two QHBoxLayouts and a QVBoxLayout. Ths size of the buttons are defined from the layout, that is
the usual way and the idea of a layout. If you want to have a fixed size for
the area of the buttons, put the layout in a QFrame with fixed size, then all
sizes are defined from this. -
The size of the QGridLayout is dictated by the size of the container it is applied to. The grid layout allocates the space it has available to the widget it controls. If you stick 2*12 equal fixed-size widgets into the grid layout they will, by default, all get exactly the same space allocated to them. If there is sufficient space then the widgets with be surrounded evenly by the spare space.