hi,

i have a QLabel and loaded a picture in it. Now i'd like to realize that a user can select a part of the picture. Therefore i captured the mouseevents over the label and could save the selection in another QLabel (like clipping).
So far, everything works fine, but now i want to visualize the selection the user is doing while he has pressed the mouse over the picture. I tried using a QPainter like this:

QRectF rectangle(leftUpperX, leftUpperY, rightLowerX, rightLowerY);
QPainter painter(this);
painter.drawRect(rectangle);


In the mousemove-event i got no functionality and this error:

QPainter::begin: Widget painting can only begin as a result of a paintEvent

So i tried to put in into an paint-Event:

void InitialLabel::paintEvent(QPaintEvent* event) {

QRectF rectangle(10.0, 20.0, 200.0, 200.0);
QPainter painter(this);
painter.drawRect(rectangle); // drawing code

}


But now the picture is no longer shown, only the rectangle.

What i would like is a variable rectangle while the mouse button is held that fixes it's position when the mouse button is released.
This should be on top of the picture, so that a user can see the picture in the background while he makes his selection.

Anyone who can help me with this?

Thanks in advance.