Hello,

I'm currently writing a small drawing application using a QGraphicsView. My goal is to achieve a "drawing zone" like in photoshop for instance.
I've created a QGraphicsRectItem class for my canvas that displays an image on which I can paint (by overriding the paint method). This canvas is added on my custom QGraphicsView. In that later I have overrides for the mouse events that I transmit to the canvas through my own methods. It implies that I always need to recalculate my mouse location according to the canvas position in the view like that:

Qt Code:
  1. QPointF View::mapToCanvas(QPointF pos)
  2. {
  3. QPointF canvasOffset = mapFromScene(canvas->pos());
  4. return QPointF((pos - canvasOffset) / scaleFactor);
  5. }
To copy to clipboard, switch view to plain text mode 

I also started to implement a Panning, Zooming and a Reset view feature but it's not working very well and implies some heavy code.

For the zoom, I've used the scale method of the view, it works quite well and the scroll bars of the view are working too

For the panning I've done a moveBy on the canvas in the mouseMoveEvent:

Qt Code:
  1. if(panCanvas) //set to true in mousePressEvent and back to false in mouseReleaseEvent
  2. {
  3. canvas->moveBy((event->pos() - lastMousePos).x() / scaleFactor,(event->pos() - lastMousePos).y() / scaleFactor);
  4. }
To copy to clipboard, switch view to plain text mode 

But in this case when the canvas is out of "window" the scroll bars are not showing up.

I've tried many things but I cannot find a clean looking solution. For instance I tried using this method: setDragMode(ScrollHandDrag); but it's not doing anything in my case :/

What do you think I should do ?

Thank you for your time, have a nice day/night

Panicq