PDA

View Full Version : Show portion of an image



ucntcme
21st May 2010, 19:13
I'm given an image that represents stages/levels along these lines. Each stage is represented as an complete "image" at the percentage and then copied vertically within the actual image file. Perhaps some ascii art will help with that poor description.



##########
#########_
########__
#######___
######____
#####_____
####______
###________
##_________
#__________



Each line in there represents a "sub image" - think similar to a fuel gauge.

What I need to do is to display one sub image, one "line", based on some other data.

I *could* do it by breaking the image up into separate images for each level[1], but I'd rather do it by showing a piece, given that the image may change and I'd rather avoid the manual step and recompile and just get the base image via http. I've got the retrieve and show part down, just need to know how to show the "sub image".

I suspect I need a QGraphicsScene but I've not teased it out of the docs yet.

1. If needs be i'll break it into individual images, and using a stacked widget with a QLabel showing the image, since the incoming condition data is integer based.

jryannel
22nd May 2010, 09:10
Hi,

You could just load the whole image and cut the image into pieces. E.g. QPixmap::copy(size). You want to use QPixmap in the end so that you graphics data resides in the graphics memory. After this I would create a custom widget, where you can set a pixmap list on and only the active index is shown. Please bear in mind that QPixmaps are implicit shared and they always should be created on the stack!



public LevelWidget : public QWidget {
void setImages(QList<QPixmap> images) // your cutted images
void setCurrentIndex(int index); // which image to be painted
void paintEvent(QPaintEvent) // paint the current image here
};