Unsolved Space Buttons equally in Layout, but with an empty slot
-
@JonB
as it would distribute the space evenly ? Or did i miss the point ?
-
@mrjj
I think you absolutely did not miss the point, and that looks very pretty :) -
@JonB
Ok, thats good. very hot here and brain a bit fried :) -
@mrjj
I don‘t know why the op says a Qqspacer didn‘t work.
This is exactly why they exist.A Qwidget will do it, as you‘ve shown, but a spacer will too, with much less overhang ☺️
-
@J.Hilk
The OP wrote/claimed:I have tried to use Spacers, but it seems like those require a specific height and weight
So that should not have been the case?
-
Hi
well spacer could do the same but requires more fiddling as its greedy and compresses the
the ends so dont work the same "out of the box" but im sure it can be adjusted to do the same.
-
mmh, not to tricky in my opinion x):
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QVBoxLayout *vLayout = new QVBoxLayout(ui->centralWidget); for(int i(0); i < 5; i++){ QPushButton *btn(new QPushButton(QString("Button %1").arg(i))); btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); vLayout->addWidget(btn,1); } QSpacerItem *spacer = new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::Expanding); vLayout->addItem(spacer); vLayout->setStretch(5,1); QPushButton *btn(new QPushButton(QString("Last Button"))); btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); vLayout->addWidget(btn,1); }
sry, don't know of an easy way to make a gif on the fly. X)
-
@J.Hilk said in Space Buttons equally in Layout, but with an empty slot:
mmh, not to tricky in my opinion x):
Just to clarify, the central point here is that the buttons and the spacer have the same vertical size policy (doesn't have to be "expanding").
-
@VRonin
true,
but if it's not set to expanding, thesizeHint
would also have to be the same for Spacer and Button, right? -
@mrjj Is your first example using a GridLayout? Or a vertical layout? When I place the buttons and a widget in the form and combine into a QVBoxLayout or a QGridLayout, shrinking and expanding the layout only changes the height of the widget, not the buttons.
-
@Smeeth
Hi noticed the buttons come default with Fixed as policy. I changed that for that sample.