Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Setting layers of QPixmaps on a QGraphicsItem?



  • I have this code:

    @QBrush newbrush;

    newbrush.setTexture((QPixmap(":/pics/background.png")).scaled(50,50,Qt::KeepAspectRatio, Qt::FastTransformation));

    painter->setBrush(newbrush);

    painter->drawPixmap(0,0,(QPixmap(":/pics/character.png")).scaled(50,50,Qt::KeepAspectRatio, Qt::FastTransformation));

    painter->drawRoundedRect(0,0,50,50,5,5);@

    It's messy, yes, but this is just testing around. So basically that's in a private function of a QGraphicsItem that displays a rectangle. Ideally I would like to have the newbrush as a background texture and then add the other pixmap on top of the background, to make it look like I have a character on top of a texture. This works to some degree only. When I run that code, it draws the newbrush but not the character. When I set lines 3 and 5 into comments, it draws the character. So this makes me think that it draws the character under the background. How can I make it so that background is drawn on to the rectangle and then the character is drawn on top of the background?


Log in to reply