I tried to create a custom board background for 2048, when I ran it in Debugger Mode, gbp points to this line "for (int row = 0; row < SIZE; ++row)", which is very confusing for me
#include "guiboard.hh"
guiboard::guiboard(QObject* parent)
: QGraphicsScene(parent)
{
setSceneRect(50, 200, BOARD_SIZE, BOARD_SIZE);
}
void guiboard::make_bg()
{
QPixmap image(QString::fromStdString("wood.jpg"));
// Scaling the pixmap
image = image.scaled(BOARD_SIZE, BOARD_SIZE);
addPixmap(image);
QPen pen;
pen.setBrush(Qt::gray); pen.setWidth(3);
for (int row = 0; row < SIZE; ++row)
{
for (int col = 0; col < SIZE; ++col)
{
int ax = 50 + SPACING + row * SPACING + row * TILE_SIZE;
int ay = 200 + SPACING + col * SPACING + col * TILE_SIZE;
addRect( ax, ay, TILE_SIZE, TILE_SIZE, pen, QColor::fromRgb(0, 0, 0));
}
}
}
Here is the MainWindow
#include "mainwindow.hh"
#include "ui_mainwindow.h"
#include <QGraphicsView>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, gameboard()
{
ui->setupUi(this);
ui->stackedWidget->setCurrentIndex(1);
ui->boardDM->setGeometry(50, 200, 500, 500);
gameboard->make_bg();
ui->boardDM->setScene(lauta);
}
MainWindow::~MainWindow()
{
delete ui;
}
(I'm on my baby steps to learn C++, so detailed explanation is much appreciated. Thank you!)
Aucun commentaire:
Enregistrer un commentaire