Hi everybody. I've poked a bit at QT before but I'm really a newbie. Now I'm attempting to put together a version of the classic minesweeper game.
This kind of game really needs square cells in the grid. I thought I could get that by applying the "heightforwidth" property to the qpushbuttons that make up each tile.
Here's an example of what I get:
Screenshot_2021-09-07_11-09-44.jpg
Here's the code for the cell:
{
bool Bomb;
GridPos Pos;
public:
GridCell() {}
virtual ~GridCell() {}
{
Pos = P;
GridLayout->addWidget(this, Pos.y, Pos.x);
p.setHeightForWidth (true);
p.setHorizontalStretch (1);
p.setVerticalStretch (1);
setSizePolicy (p);
setText("K");
}
void SetBomb (bool B = true)
{
Bomb = B;
}
bool IsBomb ()
{
return Bomb;
}
};
class GridCell : public QPushButton
{
bool Bomb;
GridPos Pos;
public:
GridCell() {}
virtual ~GridCell() {}
GridCell (QGridLayout *GridLayout, const GridPos &P) : QPushButton ()
{
Pos = P;
GridLayout->addWidget(this, Pos.y, Pos.x);
QSizePolicy p(sizePolicy());
p.setHeightForWidth (true);
p.setVerticalPolicy (QSizePolicy::Expanding);
p.setHorizontalPolicy (QSizePolicy::Expanding);
p.setHorizontalStretch (1);
p.setVerticalStretch (1);
setSizePolicy (p);
setText("K");
}
void SetBomb (bool B = true)
{
Bomb = B;
}
bool IsBomb ()
{
return Bomb;
}
};
To copy to clipboard, switch view to plain text mode
I've tried a lot of different things but guess I'm misunderstanding some fundamental concept.
A little help please?
Bookmarks