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.


  • Qt Champions 2016

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

    Add a signal to your graphicview class

    signals:
        void MWheelActivated(bool ZoomIn);
    

    and hook it up to a slot in your mainwindow with the connect function.
    http://doc.qt.io/qt-5.5/signalsandslots.html

    then in GraphicsView::wheelEvent(QWheelEvent *e)
    you
    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.