You have to subclass QLabel and reimplement mousePressEvent, mouseMoveEvent and paintEvent.
In mousePressEvent: store the crop coordinates in a QRect or two QPoint's. The local coordinates are stored in the event.
When you receive the right click(you should implement some kind of click counting - a boolean flag, etc) you have the two local coordinates. Now you can crop the pixmap and set it in the label.
In mouseMoveEvent: after you have the coordinate for the left mouse click you can update the second coordinate with the current mouse position stored in the event.
In paintEvent: draw the crop rectangle specified by the left click position and right click position or current mouse position(if you didn't have a right click yet). Note that you first have to call QLabel:aintEvent and then draw your crop rectangle, because you want the label to be able to draw its initial contents.
As for storing the pixmaps, you can do that with a 1 QPixmap member, for the original image.




aintEvent and then draw your crop rectangle, because you want the label to be able to draw its initial contents.
Reply With Quote
mousePressEvent(), mouseMoveEvent() and paintEvent(). Is it also going to create the m_pixmapLabel instance? If I put this in the QLabel subclass it needs to be in the appropriate constructor, meaning that I cannot add it to my mainLayout (which is subclassed in MyWidget).
Bookmarks