Zoom function on QWidget

I have a QWidget where I draw a few lines and I would like to enable / implement the zoom function to better see the image I draw. And I want to associate this with the mouse wheel, as in normal browsers, when you can zoom in and out by pressing the "ctrl" key and turning the mouse wheel.

Is there a default function for this? I tried to find some examples, but no luck. So how can I do this?

+4
source share
1 answer

Try overriding your paintEvent and apply a scale to the QPainter before drawing.

class YourClass:public QWidget { ... protected: void paintEvent ( QPaintEvent * event ); void wheelEvent ( QWheelEvent * event ); private: qreal scale; }; void YourClass::paintEvent ( QPaintEvent * event ) { QPainter p; p.scale(scale,scale); // paint here } void YourClass::wheelEvent ( QWheelEvent * event ) { scale+=(event->delta()/120); //or use any other step for zooming } 
+14
source

All Articles