Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphics Item is under the background.
Forum Updated to NodeBB v4.3 + New Features

QGraphics Item is under the background.

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 940 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    browser90
    wrote on last edited by
    #1

    Hi guys,

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

    @
    worldImage.fill(1);

    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;
            }
        }
    }
    
    painter.drawImage(0,0,background);
    
    if(item != NULL)
    {
        delete item;
        item = NULL;
    }
    
    //adding new image to the graphicsScene
    item = new QGraphicsPixmapItem( QPixmap::fromImage(worldImage));
    this->addItem(item);
    
    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++)
        {
            this->addItem(getWorm(pGame->getCurrentState(),pGame->getPlayer(pGame->getCurrentState())->findWorm(activeWorm)));
            activeWorm = pGame->getPlayer(i)->getWorm(j);
        }
    }   
    

    @

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

    Kind regards,

    1 Reply Last reply
    0
    • B Offline
      B Offline
      browser90
      wrote on last edited by
      #2

      just found the problem:

      item->setZValue(-1);
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved