Space Buttons equally in Layout, but with an empty slot
-
@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 ☺️
-
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.
-
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)
-
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").
-
@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").
-
@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.
-
@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.