diff --git a/assignments/06/ThinkPink/mainwindow.cpp b/assignments/06/ThinkPink/mainwindow.cpp index 4cca7b5..534b722 100644 --- a/assignments/06/ThinkPink/mainwindow.cpp +++ b/assignments/06/ThinkPink/mainwindow.cpp @@ -3,6 +3,12 @@ extern std::unique_ptr settings; +// event functions +void MainWindow::buttonPressed(QPushButton *button) { + QString text = "owo"; + button->setText(text); +} + // initialisation functions void MainWindow::initialiseGameGrid() { qDebug() << "Number of rows: " << n_rows; @@ -11,6 +17,21 @@ void MainWindow::initialiseGameGrid() { for (long long i = 0; i < colors.size(); i++) { qDebug() << colors.value(i); } + + for(int i = 0; i < n_columns; i++) + { + for(int j = 0; j < n_rows; j++) + { + QPushButton * button = new QPushButton(this); + ui->gameGridLayout->addWidget(button, j, i); + + // Set size text etc. for each button + + connect(button, &QPushButton::clicked, [=](){ + buttonPressed(button); + }); + } + } } void MainWindow::initialiseWindow() { diff --git a/assignments/06/ThinkPink/mainwindow.h b/assignments/06/ThinkPink/mainwindow.h index a4ecdf9..f7a1bc1 100644 --- a/assignments/06/ThinkPink/mainwindow.h +++ b/assignments/06/ThinkPink/mainwindow.h @@ -6,6 +6,7 @@ #include #include +#include #include QT_BEGIN_NAMESPACE @@ -24,6 +25,9 @@ public: void initialiseWindow(); void initialiseMenuBar(); + // events + void buttonPressed(QPushButton *button); + private: Ui::MainWindow *ui; const int n_rows;