如何强制 gridLayout 使每个单元格大小相同?另外我如何摆脱不必要的间距?

How do I force gridLayout to make each cell the same size? Also how do I get rid off unnecessary spacing?

The application

如您所见,它并没有使按钮同样大。尽管我用这些属性创建了它们

butt->setMaximumHeight(50);
butt->setMaximumWidth(50);
butt->setMinimumHeight(50);
butt->setMinimumWidth(50);

以确保它们具有我想要的确切尺寸。

这是我创建按钮的代码部分:

for (int r = 0; r < 10; r++){
        for (int c = 0; c < 10; c++)
        {
            QPushButton *butt = new QPushButton();
            butt->setMaximumHeight(50);
            butt->setMaximumWidth(50);
            butt->setMinimumHeight(50);
            butt->setMinimumWidth(50);
            ui->gridLayout->addWidget(butt, r, c);
            gameTable[r][c] = butt;
        }
    }

这里,gameTable定义如下:

QPushButton *gameTable[10][10];

此外,如您所见,列之间有空格。我该如何摆脱它们?

要使 gridLayout 的行为符合预期,有必要将大小约束设置为固定:

ui->gridLayout->setSizeConstraint(QLayout::SetFixedSize);