这是我生成棋盘的简单代码。首先是添加的矩形,就像放置图形的地方一样。接下来,QPixmap,包含图形的 png 显示在上面。我没有看到一些数字,因为它们在那个矩形之下。如果我在注释行中添加 rect (scene->addRect...),它看起来很好。为什么?我正在按照应该显示的项目进行绘画。
for (int column = 0; column < 8; column++) {
if ((row + column) % 2) {
scene->addRect(row * 50, column * 50, 50, 50, greyPen, greyBrush);
}
else {
scene->addRect(row * 50, column * 50, 50, 50, whitePen, whiteBrush);
}
int figure = chessboard->getFigureOnPos(row, column);
if (figure == Dama::Chessboard::DAMA_BLACK) {
QGraphicsItem * item = scene->addPixmap(dama_black);
item->setPos(column * 50, row * 50);
}
else if (figure == Dama::Chessboard::DAMA_WHITE) {
QGraphicsItem * item = scene->addPixmap(dama_white);
item->setPos(column * 50, row * 50);
}
else if (figure == Dama::Chessboard::PANAK_BLACK) {
QGraphicsItem * item = scene->addPixmap(panak_black);
item->setPos(column * 50, row * 50);
}
else if (figure == Dama::Chessboard::PANAK_WHITE) {
QGraphicsItem * item = scene->addPixmap(QPixmap(panak_white));
item->setPos(column * 50, row * 50);
}
}