Interactively editing an existing rectangle on a QPixmap?

十年热恋 提交于 2019-12-09 08:04:18

In order to get the red selection rectangle, Qt provides the class QRubberBand. The docs state:

The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary.

By subclassing the image object and implementing the mouse handling functions, to create the rubber band on mousePressEvent, update its position on mouseMoveEvent and grab its final rect on mouseReleaseEvent, the QRubberBand will simplify the problem.

If you want the QRubberBand to show all the time, just create it when you display the enlarged image and don't hide it on releasing the mouse button.

As for displaying the image in the QGraphicsView, the code you displayed doesn't set the geometry of the QGraphicsScene and QGraphicsView, so you're seeing a border. If you don't want that, you should set them accordingly. Also note that QGraphicsView has a function fitInView, which you could use, after having retrieved an area from the QRubberBand, in order to zoom into the selected area.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!