Zooming in paintevent
-
i am new to qt.please help me out.
i have drawn one gui in paintevent on mainwindow.now i want to zoom the gui such that my gui have 4 arrow buttons and i can see my zooming in any direction using arrow buttons.
please tell me how can i do it by giving me small example by drawing rectangle and then zooming it using arrow buttons..any help will be appreciated.
thankyou. -
There isn't a trivial solution to what you want to to.
What do you mean with "i have drawn one gui in paintevent on mainwindow"? Didn't you "set a central widget":http://qt-project.org/doc/qt-4.8/qmainwindow.html#setCentralWidget of the mainwindow? Did you override QMainWindow's paintEvent handler?
For the zooming rectangle you can check out "QRubberBand":http://qt-project.org/doc/qt-4.8/qrubberband.html class.
I also think you would be better off by using QGraphicsView as your canvas and zoom in there. Since it provides you with all you need (incl. event position translation, ... )
-
thanks for your suggestion and for your concern.
i mean that i have created 4 widgets on ui on mainwindow by drag and drop and i have drawn some circles on every widget .now i want to zoom the figure which i have drawn on different widgets.and i want some arrow buttons on which if i click,i can see my scrolling in that direction....
please help me in doing that as i have stuck in this portion of my project.
thankyou -
and you want to zoom every widget's circle individually? Or zoom them altogether at once?
-
i want to zoom them altogether...please help me sir... :(send me a code which is as simple as possible.
i have drawn my figures using paintevent....thankyou
-
There is no simple/short code example, but there are plenty of tutorials about "QGraphicsView":http://qt-project.org/doc/qt-4.8/qgraphicsview.html on the web.
All you need to to is to "add your circles":http://qt-project.org/doc/qt-4.8/qgraphicsscene.html#addEllipse to the QGraphicsScene. For simplification you can see the QGraphicsItems as QWidgets in your canvas.Finally you "zoom":http://qt-project.org/doc/qt-4.8/qgraphicsview.html#scale your QGraphicsView (calculate the zooming-value from the ratio of QRubberBand rect to the viewport rect).