16,212
社区成员
发帖
与我相关
我的任务
分享
class ChessBoard : public QLabel
{
Q_OBJECT
public:
explicit ChessBoard(size_t row,size_t column,QWidget *parent);
bool draw_board();
signals:
void clicked(size_t, size_t);
public slots:
protected:
void mouseReleaseEvent(QMouseEvent *ev);
~ChessBoard(){}
private:
size_t row;
size_t column;
static const size_t padding = 20;
static const size_t interval = 35;
};
QGridLayout *layout = new QGridLayout();
layout->addWidget(board,0,0,1,1);
layout->addWidget(ui->go_exit,0,1,1,1);
layout->takeAt(0);
qDebug()<<
this->setLayout(layout);
void clientWidget::paintEvent(QPaintEvent *event)
{
ui->stackedWidget->currentWidget()->layout();
if(game != GO && game!=FIVE) {
// qDebug()<<"dag";
return;
}
//qDebug()<<"paint";
int GridSize=(height()-60)/18;
QPainter p(this);//感觉是这里出了问题,应该画到棋盘上才对,我不会弄。。。
QPen pen;
QBrush brush;
pen.setWidth(2);
pen.setColor(Qt::black);
p.setPen(pen);
//画棋子
int size;
if(game==GO){
size=Go->boardSize();
}else if(game==FIVE){
size=Five->boardSize();
}
for(int i=0;i<size ;i++){
for(int j=0;j<size ;j++){
StoneType current;
if(game==GO){
current= Go->checkStone(i,j);
}else if(game==FIVE){
current= Five->checkStone(i,j);
}
if(current==BLACK){
brush.setColor(Qt::red);
p.setBrush(brush);
p.drawEllipse(QPoint((i)*GridSize+30,(j)*GridSize+30),12,12);
}
else if(current==WHITE){
brush.setColor(Qt::white);
p.setBrush(brush);
p.drawEllipse(QPoint((i)*GridSize+30,(j)*GridSize+30),12,12);
}
}
}
this->children()
}