Qt World Summit: Submit your Presentation

QT grid layout top left

  • 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.

  • @DevM
    Not so far as I know from usage (hence the other person creating a custom layout).

    EDIT I understood your question to be wanting to achieve this in Qt Designer!

  • 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.

  • @JackTr

    Your solution does somehow help or it gets close enough to what I want

    code doing it:

        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 Champion

    @DevM said in QT grid layout top left:

    Is it possible to change the spacing between those widgets though?

    Only by making the widgets bigger or the layout area smaller.

    I was wondering if this example layout is close to what you want ?

Log in to reply