c++ - QT - QGraphicsScene doesn't show properly (z-buffer?) -
this simple code generating chessboard. first added rects acting place figure. next, qpixmap, containing png of figure displayed over. don't see figures, because under rects. if put comment lines adding rect (scene->addrect...) looks fine. why? painting in order in wich items should displayed.
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); } }
qgraphicsitem has function called setzvalue set stacking order of items higher valued item draw on top. default, items set zero. if items in correct position in scene, set z value of figures higher value rects.
Comments
Post a Comment