You need to draw a picture on the bitmap before to add it to the scene. When you add it to the scene, the scene will use it to create the QGraphicsPixmapItem object, which is also returned by the addPixmap() function. If you want to update pixmap after adding it, you need to call the setPixmap() function of the returned QGraphicsPixmapItem object.
So either:
... QPixmap *pix = new QPixmap(500,500); QPainter *paint = new QPainter(pix); paint->setPen(*(new QColor(255,34,255,255))); paint->drawRect(15,15,100,100); scene->addPixmap(*pix);
or
... QPixmap *pix = new QPixmap(500,500); QGraphicsPixmapItem* item(scene->addPixmap(*pix)); // Save the returned item QPainter *paint = new QPainter(pix); paint->setPen(*(new QColor(255,34,255,255))); paint->drawRect(15,15,100,100); item->setPixmap(*pix); // Added this line ...
Daniel Hedberg
source share