Results 1 to 8 of 8

Thread: Zoom functionality on pushbutton

  1. #1
    Join Date
    Dec 2012
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Zoom functionality on pushbutton

    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 .......

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Zoom functionality on pushbutton

    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
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Dec 2012
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Zoom functionality on pushbutton

    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 ......

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Zoom functionality on pushbutton

    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?

    Qt Code:
    1. //main.cpp
    2. #include <QWheelEvent>
    3. #include <QMainWindow>
    4. #include <QApplication>
    5. #include <QGraphicsView>
    6. #include <QGraphicsScene>
    7.  
    8. class View : public QGraphicsView
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. explicit View(QWidget *parent) : QGraphicsView(parent),
    14. h11(1.0), h12(0), h21(0), h22(1.0) {}
    15.  
    16. protected:
    17. void wheelEvent(QWheelEvent *event);
    18.  
    19. private:
    20. qreal h11;
    21. qreal h12;
    22. qreal h21;
    23. qreal h22;
    24. };
    25.  
    26. void View::wheelEvent(QWheelEvent *event)
    27. {
    28. if(qApp->keyboardModifiers() & Qt::ControlModifier)
    29. {
    30. const int degrees = event->delta() / 8;
    31. int steps = degrees / 15;
    32.  
    33. double scaleFactor = 1.0;
    34. const qreal minFactor = 1.0;
    35. const qreal maxFactor = 10.0;
    36. if(steps > 0)
    37. {
    38. h11 = (h11 >= maxFactor) ? h11 : (h11 + scaleFactor);
    39. h22 = (h22 >= maxFactor) ? h22 : (h22 + scaleFactor);
    40. }
    41. else
    42. {
    43. h11 = (h11 <= minFactor) ? minFactor : (h11 - scaleFactor);
    44. h22 = (h22 <= minFactor) ? minFactor : (h22 - scaleFactor);
    45. }
    46.  
    47. setTransformationAnchor(AnchorUnderMouse);
    48. setTransform(QTransform(h11, h12, h21, h22, 0, 0));
    49. }
    50. else
    51. {
    52. QGraphicsView::wheelEvent(event);
    53. }
    54. }
    55.  
    56. int main(int argc, char *argv[])
    57. {
    58. QApplication a(argc, argv);
    59. QMainWindow mainWindow;
    60. QColor colors[] = {Qt::red, Qt::blue, Qt::black, Qt::green, Qt::yellow };
    61. int color = 0;
    62.  
    63. QGraphicsView *view = new View(&mainWindow);
    64. QGraphicsScene *scene = new QGraphicsScene(&mainWindow);
    65. QPen pen;
    66. pen.setWidth(4);
    67.  
    68. for(int i = 0; i < 2000; i += 150)
    69. {
    70. for(int j = 0; j < 2000; j += 150)
    71. {
    72. pen.setColor(colors[color++ % 5]);
    73. scene->addRect(i, j, 100, 100, pen);
    74. scene->addEllipse(i, j, 100, 100, pen);
    75. }
    76. }
    77.  
    78. view->setScene(scene);
    79. mainWindow.setCentralWidget(view);
    80.  
    81. mainWindow.showMaximized();
    82.  
    83. return a.exec();
    84. }
    85.  
    86. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    Last edited by Santosh Reddy; 7th January 2013 at 10:44. Reason: Changed View::View() definition
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Dec 2012
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Zoom functionality on pushbutton

    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

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Zoom functionality on pushbutton

    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?
    Last edited by Santosh Reddy; 7th January 2013 at 10:48.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  7. #7
    Join Date
    Dec 2012
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Zoom functionality on pushbutton

    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
    Last edited by chirudi; 8th January 2013 at 04:30.

  8. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Zoom functionality on pushbutton

    and what is graphicsscene rect size?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 3
    Last Post: 29th April 2011, 08:54
  2. how to zoom in zoom out tableview in QT programming?
    By nageshvk in forum Qt Programming
    Replies: 0
    Last Post: 27th October 2010, 05:05
  3. QWTPlot Zoom: cannot zoom negative value
    By jwieland in forum Qwt
    Replies: 0
    Last Post: 8th January 2010, 16:16
  4. Replies: 1
    Last Post: 16th November 2009, 05:25
  5. QGLWidget with text - zoom in / zoom out
    By h123 in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2008, 09:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.