0
這是我生成棋盤的簡單代碼。首先是增加了像人物地方一樣的rects。接下來,顯示包含圖的png的QPixmap。我沒有看到一些數字,因爲它們是在這種情況下。如果我在註釋行中添加rect(場景 - > addRect ...),它看起來很好。爲什麼?我正在繪畫,以顯示至極的項目。QT-QGraphicsScene不能正確顯示(z-buffer?)
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);
}
}