Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to zoom into a specific point in an image?
QtWS25 Last Chance

How to zoom into a specific point in an image?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    UbiMiles
    wrote on 29 Mar 2022, 09:07 last edited by
    #1

    I'm using a wheelEvent and a paintEvent to implement zooming functionality into an image , I use a custom class derived from QLabel and paint to it in my paintEvent
    my question is how can I zoom into a specific point instead of (0,0) changing x,y for the drawImage function shifts my whole image out of the component
    here is my code for refrence

    void zoompan::paintEvent ( QPaintEvent * event )
    {
        QPainter p(this);
         p.scale(scale,scale);
        //paint here
         p.drawImage(0,0,img);
    }
    
    void zoompan::wheelEvent ( QWheelEvent * event )
    {
        scale+=event->angleDelta().y()/240.0;
        origin=event->position();
        if(scale<1)
        {
            scale=1;
            origin=QPointF(0,0);
        }
        update();
    }
    
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 29 Mar 2022, 19:32 last edited by
      #2

      Hi,

      Do you mean grab the mouse pointer position to start the zoom ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      U 1 Reply Last reply 30 Mar 2022, 10:29
      1
      • S SGaist
        29 Mar 2022, 19:32

        Hi,

        Do you mean grab the mouse pointer position to start the zoom ?

        U Offline
        U Offline
        UbiMiles
        wrote on 30 Mar 2022, 10:29 last edited by
        #3

        @SGaist
        how to zoom at the mouse position rather, grabbing it from the wheel event is where I got , now I am stuck trying to zoom into that point..

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 30 Mar 2022, 19:56 last edited by
          #4

          I just realised something, you would likely simplify your life using the Graphics View framework.

          You have an example here.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          U 1 Reply Last reply 31 Mar 2022, 13:41
          2
          • S SGaist
            30 Mar 2022, 19:56

            I just realised something, you would likely simplify your life using the Graphics View framework.

            You have an example here.

            U Offline
            U Offline
            UbiMiles
            wrote on 31 Mar 2022, 13:41 last edited by
            #5

            @SGaist
            a QLabel would be way more efficient I believe given that I keep updating the images
            creating a pixmap item for each image would be a bit of an overhead I would imagine

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 31 Mar 2022, 18:49 last edited by
              #6

              You can replace the content of the time with QGraphicsPixmapItem::setPixmap.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              U 1 Reply Last reply 4 Apr 2022, 01:30
              1
              • S SGaist
                31 Mar 2022, 18:49

                You can replace the content of the time with QGraphicsPixmapItem::setPixmap.

                U Offline
                U Offline
                UbiMiles
                wrote on 4 Apr 2022, 01:30 last edited by
                #7

                @SGaist
                I see , thanks !

                1 Reply Last reply
                0

                1/7

                29 Mar 2022, 09:07

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved