QGraphics Item is under the background.

  • Hi guys,

    I've got a function that creates me a background and gives me a bitmap off the background something like this:


    QPainter painter(&worldImage);
    sizeImage = background.size();
    width = sizeImage.width();
    height = sizeImage.height();
    for(int y = 0; y < height; y++) {
        for(int x = 0; x < width; x++) {
            color = background.pixel(x,y);
            if (qRed(color) == 0 && qGreen(color) == 0 && qBlue(color) == 0) {
                background.setPixel(x,y,QColor(Qt::blue).rgb()); // Qt::blue is a QColor constant.
                bitmap[x][y] = 0;
    if(item != NULL)
        delete item;
        item = NULL;
    //adding new image to the graphicsScene
    item = new QGraphicsPixmapItem( QPixmap::fromImage(worldImage));
    updateWormsAfterDamamge(); //Put the worms back on the screen after the damage.


    Works fine but the last function upDateWormsAfterDamage, must do that the already made graphics items are on top of the background but they aren't, the background is only shown. Is Qt deleting all the graphics items off the scene after updateworld or is it drawning on top of it? Is it possible to let updateWorms draw on top off the background?

    THis is the updateworms function::
    Worm * activeWorm = pGame->getActiveWorm();

    for(int i = PLAYER1; i <= PLAYER2; i++)
        for(int j = 0; j < pGame->getPlayer(i)->numWorms(); j++)
            activeWorm = pGame->getPlayer(i)->getWorm(j);


    where getworm get's the QImageItem to be added on the scene;

    Kind regards,

  • just found the problem:


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.