I have created a preview that shows a rendered image. I used the Image Viewer Example for zooming functionality - so I have a class inheriting QScrollArea
, capable of showing an image, in a QLabel
, and zooming in/out/fit with specific limits. I was showing scrollbars "as needed".
As a new requirement, I must be able to do panning, and not show scrollbars.
I have been looking for ways to do it - and found examples of people using mouse press, move and release events to relate a point on the image to scrollbars.
The problems:
1) the direction of move, if scrollbars are invisible, is unexpected - in panning he object moves in the direction of the mouse (stays under mouse), while scrollbars move in the opposite direction
2) I think the move is limited to scrollbar size so... if I calculate a reverse move, I would hit a wall while still have room to move in one direction
3) This would not work with zooming, which is exactly when the panning is needed; more complex calculations would be needed.
I could alternately use a QGraphicsView
, and
setDragMode(ScrollHandDrag);
It would work nice with zooming as well, and I would not have to implement it myself.
The reason I have not done this yet is, I would need to add a QGraphicsScene
as well, and a QGraphicsPixmapItem
containing the image I want - then find how to disable all mouse events other than panning - and still use a QScrollArea
to hold the QGraphicsView
;
It seems it is too much overhead (and this is meant to be extremely light-weight, for an embedded device with little speed and memory).
What is the best option ? is there some way I can pan a zoomed image in a viewer, as light weight as possible ?