PDA

View Full Version : QGraphicsPixmapItem to QPixmap to QImage and back again!



bruceariggs
10th September 2011, 00:21
I have a giant image cut into tile pieces.

The tile pieces store a QGraphicsPixmapItem that has been added to a scene.

On rare occassions, the user may choose to change the color table the image is using.

When the user chooses to change the colors, I attempt to change the QGraphicsPixmapItem in the following manner:

image = QGraphicsPixmapItem*
table = QVector<QRgb> (passed in from a function)


QPixmap tempPixmap = image->pixmap();

QImage tempImage = tempPixmap.toImage();

tempImage.setColorTable( table );

tempPixmap = tempPixmap.fromImage( tempImage );

image->setPixmap( tempPixmap );

Now since these Pixmaps have already been added to the scene, shouldn't they draw under the new color scheme?

After this function runs, nothing changes on the display. It's still on the old color scheme.

Any help would be much appreciated.

stampede
10th September 2011, 09:26
After this function runs, nothing changes on the display.
Does it change the image ? You can save it on disk and see the result.

bruceariggs
10th September 2011, 14:08
Yes, it does change the image. I used the save function to output the whole image before and after conversion and the images were different, yet the display never changed.

HOWEVER, I did solve this issue while making optimizations.

I was being silly and converting each tile piece to QImage and back, so I figured, "Why not just do the slow change once on the whole image", so I now do the color change on the entire image just once, instead of millions of times, and now for some reason the color change is showing up.

So... Whatever. Maybe the original problem had something to do with a variable falling out of scope or what-not, but it doesn't matter now, the issue is resolved. =)

Thank you for your help, though.