QT grid layout top left
-
wrote on 3 Apr 2020, 11:49 last edited by
Hey,
Is there any way to make a grid layout start filling by top-left so that I have something like this (only works because I have filled the grid)
I have seen another answer in which someone created a custom layout but before I go that route I would like to know if there's something I can do in the designer itself.
-
Hey,
Is there any way to make a grid layout start filling by top-left so that I have something like this (only works because I have filled the grid)
and not this
I have seen another answer in which someone created a custom layout but before I go that route I would like to know if there's something I can do in the designer itself.
-
wrote on 3 Apr 2020, 17:38 last edited by JackTr 4 Mar 2020, 17:40
I am not sure if I understood you right, but maybe this will help:
GridLayout->addWidget(pBtn,1,1,1,1,{Qt::AlignTop, Qt::Alignleft});
so the button would align in the top left corner.
In another way you could expand the buttons vertically so they take up the full space of the grid layout depending on its size with something like:
pBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
You might wanna fix the size of the QGridLayout widget so it is filled.
-
I am not sure if I understood you right, but maybe this will help:
GridLayout->addWidget(pBtn,1,1,1,1,{Qt::AlignTop, Qt::Alignleft});
so the button would align in the top left corner.
In another way you could expand the buttons vertically so they take up the full space of the grid layout depending on its size with something like:
pBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
You might wanna fix the size of the QGridLayout widget so it is filled.
wrote on 3 Apr 2020, 18:06 last edited byYour solution does somehow help or it gets close enough to what I want
code doing it:
this->ui->gridLayout_2->addWidget(uc,1,1,1,1,{Qt::AlignTop,Qt::AlignLeft}); this->ui->gridLayout_2->addWidget(new UC(this),1,2,{Qt::AlignTop,Qt::AlignLeft}); this->ui->gridLayout_2->addWidget(new UC(this),1,3,{Qt::AlignTop,Qt::AlignLeft}); this->ui->gridLayout_2->addWidget(new UC(this),1,4,{Qt::AlignTop,Qt::AlignLeft}); this->ui->gridLayout_2->addWidget(new UC(this),2,1,{Qt::AlignTop,Qt::AlignLeft}); this->ui->gridLayout_2->addWidget(new UC(this),2,2,{Qt::AlignTop,Qt::AlignLeft});
Is it possible to change the spacing between those widgets though?
-
Your solution does somehow help or it gets close enough to what I want
code doing it:
this->ui->gridLayout_2->addWidget(uc,1,1,1,1,{Qt::AlignTop,Qt::AlignLeft}); this->ui->gridLayout_2->addWidget(new UC(this),1,2,{Qt::AlignTop,Qt::AlignLeft}); this->ui->gridLayout_2->addWidget(new UC(this),1,3,{Qt::AlignTop,Qt::AlignLeft}); this->ui->gridLayout_2->addWidget(new UC(this),1,4,{Qt::AlignTop,Qt::AlignLeft}); this->ui->gridLayout_2->addWidget(new UC(this),2,1,{Qt::AlignTop,Qt::AlignLeft}); this->ui->gridLayout_2->addWidget(new UC(this),2,2,{Qt::AlignTop,Qt::AlignLeft});
Is it possible to change the spacing between those widgets though?
Lifetime Qt Championwrote on 4 Apr 2020, 06:34 last edited by mrjj 4 Apr 2020, 06:34@DevM said in QT grid layout top left:
Is it possible to change the spacing between those widgets though?
Hi
Only by making the widgets bigger or the layout area smaller.I was wondering if this example layout is close to what you want ?
https://doc.qt.io/qt-5/qtwidgets-layouts-flowlayout-example.html
1/5