Drawing the same pix map to a scene only draws the last one?



  • Hi All,
    if I load a pix map item and draw it to a scene it will only draw it works great. However if I draw the same pixmap to the scene in different locations it only draws the last one? If I draw a different pixmap it works fine. So say I load in "galaxian" and try to draw that "sprite" it will only draw the last one drawn. If I load in "firebird" it will draw both galaxian and firebird, however only one of each. So my code below will; only draw pixmapitem 0 once, if I replace the loading of sym = SpriteObjectClass.get_element_from_list( 0 ); with sym = SpriteObjectClass.get_element_from_list( 1 ); it will draw the second sprite in my list.

    Can anyone advise how I can draw the same pixmapitem multiple times to the same scene?

    Thanks

    
         SPRITE sym = SpriteObjectClass.get_element_from_list( 0 );
        scene = new QGraphicsScene( this );
    
        scene->setSceneRect( ui->graphicsView->rect() );
        ui->graphicsView->setScene( scene );
    
            sym.pixmapitem->setPos( 50, 20 );
            scene->addItem( sym.pixmapitem );
    
            sym = SpriteObjectClass.get_element_from_list( 0 );
            sym.pixmapitem->setPos( 150, 120 );
            scene->addItem( sym.pixmapitem );
    


  • Check the pointers returned by the two calls to sym.pixmapitem (before and after the get_element_from_List)
    If they point to the same object, then the behavior you describe makes perfect sense. You want to have two separate QGraphicsPixmapItems


  • Moderators

    It's the same item. addItem does not draw anything directly, it just adds it to the scene. The second call to addItem does nothing as the item is already in the scene. So basically what you're doing is: adding item to a scene , moving it to position (50,20) and then moving it again to position (150, 120).

    Moving an item doesn't result in two items being on the screen. It's like with windows. Moving a window does not mean you have two windows.


Log in to reply
 

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