From 8a381d011b97251fe5117c9906267dc18f432477 Mon Sep 17 00:00:00 2001 From: Isabell Pflug Date: Tue, 23 May 2023 23:41:38 +0200 Subject: [PATCH] :sparkles: Introduced empty button grid --- assignments/06/ThinkPink/mainwindow.cpp | 21 +++++++++++++++++++++ assignments/06/ThinkPink/mainwindow.h | 4 ++++ 2 files changed, 25 insertions(+) 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;