0

So this is the code that I have made in c++.

`

#include "mainwindow.hh"
#include "gameboard.hh"
#include "ui_mainwindow.h"
#include <iostream>

int SQUARE_SIDE_SIZE =30;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)

{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}



void MainWindow::MakeBoard(int x_len, int y_len, int SeedNumber){
    QGridLayout* grid =ui->gridLayout;

    for (int x=0; x_len>x;x++){
        for (int y=0; y_len>y;y++){
            QMainWindow* newSquare = new MainWindow(this);

            newSquare->setFixedHeight(SQUARE_SIDE_SIZE);
            newSquare->setFixedWidth(SQUARE_SIDE_SIZE);
            grid->addWidget(newSquare, x+1, y+1);


        }
    }
}




void MainWindow::on_PlayButton_clicked()
{

    QString spin = ui->spinBox->text();
    int SeedNumber = spin.toInt();

    QString Y_len = ui->spinBox->text();
    int y_len = Y_len.toInt();

    QString X_len = ui->spinBox->text();
    int x_len = X_len.toInt();

    MainWindow::MakeBoard(x_len,y_len,SeedNumber);



}

`

I would need to make some sort of a grid with this that has every other square of the grid a different colour. I have no idea how to make the grid it-self. Currently when i run this program it gives me this:enter image description here

Sanzo
  • 1
  • I think your problem has the same cause and solution as [this](https://stackoverflow.com/questions/3492739/auto-expanding-layout-with-qt-designer). The accepted answer is not completely correct though, as pointed out in a comment, you need not create a layout before the right-click. – Atmo Dec 12 '22 at 05:00

0 Answers0