Nominate our 2022 Qt Champions!

how to sync zoom in two graphicviews with a single mouse wheelevent.

  • i have a tab, in that tab, i added two frames(frame is separate class).this frame class calls the graphic view class(graphicview is also a seperate class). In the grapicsview class i am displaying images through graphicscene. this graphicsview consists of mouse wheelevent, when the mouse wheel is scrolled,the image gets zoomed in/out, my requirement is when i zoom one image both images should zoomed. please help me how to approach this, and provide your valuable suggestions or solutions. please help me.

  • Lifetime Qt Champion

    Hi and welcome
    Many ways to do this, but here is my suggestion.

    Add a signal to your graphicview class

        void MWheelActivated(bool ZoomIn);

    and hook it up to a slot in your mainwindow with the connect function.

    then in GraphicsView::wheelEvent(QWheelEvent *e)
    emit MWheelActivated ( (e->delta() > 0));
    and No zooming here!

    Then in mainwindow slot

    mainwindow:: MWheelActivated ( bool ZoomIn )
    	if ( ZoomIn ) {
    		view1->zoomIn ( 6 );
    		view2->zoomIn ( 6 );
    	} else {
    		view1->zoomOut ( 6 );
    		view2->zoomOut ( 6 );

    Hope it helps.