Dear All,
I have to do zoom functionality in my project using two pushbutton zoomin and zoomout . in my graphicsview .......
can anybody help me ........
thanking you .......
Printable View
Dear All,
I have to do zoom functionality in my project using two pushbutton zoomin and zoomout . in my graphicsview .......
can anybody help me ........
thanking you .......
It is not much different, you need to apply transformations as required. Only difference is instead of wheel event as discussed in your earlier thread, you need to trigger based of push button clicked signals
thank you boss
why i am not able to do zoom from my mouse pointer i have to do zoom to particular object ............ and i am new to it so please help me ......
Run this example, and try to point the mouse cursor at the centre of any colored circle/rectangle and sroll, then see if it zooms to the centre of same colored circle/rectange?
Code:
//main.cpp #include <QWheelEvent> #include <QMainWindow> #include <QApplication> #include <QGraphicsView> #include <QGraphicsScene> { Q_OBJECT public: h11(1.0), h12(0), h21(0), h22(1.0) {} protected: private: qreal h11; qreal h12; qreal h21; qreal h22; }; { if(qApp->keyboardModifiers() & Qt::ControlModifier) { const int degrees = event->delta() / 8; int steps = degrees / 15; double scaleFactor = 1.0; const qreal minFactor = 1.0; const qreal maxFactor = 10.0; if(steps > 0) { h11 = (h11 >= maxFactor) ? h11 : (h11 + scaleFactor); h22 = (h22 >= maxFactor) ? h22 : (h22 + scaleFactor); } else { h11 = (h11 <= minFactor) ? minFactor : (h11 - scaleFactor); h22 = (h22 <= minFactor) ? minFactor : (h22 - scaleFactor); } setTransformationAnchor(AnchorUnderMouse); setTransform(QTransform(h11, h12, h21, h22, 0, 0)); } else { } } int main(int argc, char *argv[]) { QMainWindow mainWindow; int color = 0; QPen pen; pen.setWidth(4); for(int i = 0; i < 2000; i += 150) { for(int j = 0; j < 2000; j += 150) { pen.setColor(colors[color++ % 5]); scene->addRect(i, j, 100, 100, pen); scene->addEllipse(i, j, 100, 100, pen); } } view->setScene(scene); mainWindow.setCentralWidget(view); mainWindow.showMaximized(); return a.exec(); } #include "main.moc"
Dear ,
All work well but i am not able to call Qgraphicsview Wheel event which is in else function............. i am getting
error: ‘virtual void QGraphicsView::wheelEvent(QWheelEvent*)’ is protected
What version of Qt?
I example I posted compiles and run with Qt 4.8.1 and MinGw 4.6.2.
Show us what you did?
i have QT 4.7.3(i have develop application in Linux Platform)
In my project i have taken QWidget application and on that i have added Qgraphicsview and Qgraphicsscene is added to graphicsview. and i am drawing the object in graphicsview using painterpath i have widget of size 1280x1024 . and graphicsview of 1141x991
and what is graphicsscene rect size?