QWidget* centralWidget = new QWidget(this);
setCentralWidget(centralWidget);
QVBoxLayout* mainLayout = new QVBoxLayout(centralWidget);
topLineLayout = new QHBoxLayout();
minesCounterLabel = new QLabel();
emoticonButton = new QPushButton();
timerLabel = new QLabel("0");
topLineLayout -> addWidget(minesCounterLabel);
topLineLayout -> addWidget(emoticonButton);
topLineLayout -> addWidget(timerLabel);
mainLayout -> addLayout(topLineLayout);
paddingLayout = new QGridLayout();
paddingLayout -> setSpacing(0);
std::vector <Cell> cellsVector;
for(int i = 0; i < paddingHeight; i++)
{
for(int j = 0; j < paddingWidth; j++)
{
Cell* cell = new Cell(&cellsVector, j, i, false);
cellsVector.push_back(*cell);
}
}
for(int i = 0; i < cellsVector.size(); i++)
{
paddingLayout -> addWidget(&cellsVector[i], cellsVector[i].getX(), cellsVector[i].getY());
}
mainLayout -> addLayout(paddingLayout);
Это файл mainwindow.h, и это выдержка из конструктора класса MainWindow. Чего я не понимаю, так это почему paddingLayout не показывает добавленные к нему виджеты, в данном случае «Ячейки». Любые идеи?
Редактировать:
Определение класса Cell и код его конструкторов:
class Cell : public QPushButton
{
Q_OBJECT
public:
Cell(std::vector <Cell> *, int, int, bool, QWidget* parent = 0);
Cell(const Cell&);
bool hasMine();
int getX();
int getY();
std::vector <Cell> * getCellsVector();
void setHasMine(bool);
~Cell();
Cell operator=(const Cell& object)
{
this -> cellsVector = object.cellsVector;
this -> mine = object.mine;
this -> x = object.x;
this -> y = object.y;
setFixedSize(20, 20);
connect(this, &QPushButton::clicked, this, &Cell::cellClicked);
}
private:
std::vector <Cell> * cellsVector;
int x;
int y;
bool mine;
// Determine how many mines are around this cell.
int countMines();
void cellClicked();
};
Cell::Cell(std::vector <Cell> * cellsVector, int x, int y, bool mine = false, QWidget* parent) : QPushButton(parent)
{
this -> cellsVector = cellsVector;
this -> mine = mine;
this -> x = x;
this -> y = y;
setFixedSize(20, 20);
connect(this, &QPushButton::clicked, this, &Cell::cellClicked);
}
Cell::Cell(const Cell& object)
{
this -> cellsVector = object.cellsVector;
this -> mine = object.mine;
this -> x = object.x;
this -> y = object.y;
setFixedSize(20, 20);
connect(this, &QPushButton::clicked, this, &Cell::cellClicked);
}
Если нужен еще код, скажите!