Qt blank space in QGridLayout?

I have the following code where I put the button and text box in QGridLayout. PLease notices that I use columns 3 and 4 to place them.

    QGridLayout *insAddPanel = new QGridLayout();
    {
        QLineEdit* ledInstrumentName = new QLineEdit();
        insAddPanel->addWidget(ledInstrumentName, 0, 3);

        QPushButton* btnAddInstrument = new QPushButton();
        btnAddInstrument->setText("Add");
        insAddPanel->addWidget(btnAddInstrument, 0, 4);
    }
    mainLayout->addLayout(insAddPanel);
    ......

However, when I run this, I get something like this:

enter image description here

I need the text to be edited and the button only occupy 2/5 of the available horizontal space. That is why I placed them in the 3rd and 4th columns. How it does not work, how can I do it? Is there something like an empty space widget in Qt? I searched, but did not find it.

+4
source share
3 answers
+1

QGridLayout::setColumnMinumumWidth(int column, int minSize), column minSize . . - :

insAddPanel->setColumnMinimumWidth(0, 100);    //Makes the empty column 0 100 pixels wide
insAddPanel->setColumnMinimumWidth(1, 100);    //Makes the empty column 1 100 pixels wide
insAddPanel->setColumnMinimumWidth(2, 100);    //Makes the empty column 2 100 pixels wide

100 , .

, , , , .

setRowMinimumHeight, .

0
source

Source: https://habr.com/ru/post/1527281/


All Articles