views:

36

answers:

2

Hi there,

I've been banging my head about this seemingly easy task and I could really use some help. I have a wide Image loaded in the gui (using the designer..) and I want to be able to draw only a portion of it, a rectangle. I need to be able to change this rectangle position over the large image, in order to draw a different part of the larger image at will. In this process the rect must maintain its size.

Using the Ui::MainWindow object I'm able to access the label holding the image and a solution that involves using this option is preferred (in order to keep up with the rest of the code I've already written )

Any solution will be much appreciated :)

Thanks,

Itamar

A: 

I would definitely (for ease of use) just place an empty label as placeholder in Designer.

Then implement the paintEvent for this label (delegate it to your own method). You'll have also have to look into QPainter, QPixMap, etc... Should be doable based on these hints and the documentation.

If you want more, I suggest you provide a small code snippet to work upon.

ChristopheD
Thanks for helping out.I created a label class and overloaded paintEvent.but my paintEvent is never called when i invoke repaint().Also, when I query myLabel->isVisible() I always get "False" although it is placed in the UI.
Ita
@Ita: You might not have promoted your placeholder label to the derived type.
Caleb Huitt - cjhuitt
A: 

If you want to do this more or less purely through designer, you could put a QScrollArea where you want the portion of the image to appear. If you set the scroll area's scrollbar policy to be never shown, you can then manually change what part is visible via the scroll area widget. However, this would probably be more complex that creating a derived widget and reimplementing the paint function.

Caleb Huitt - cjhuitt