Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to zoom in multiple objects?
QtWS25 Last Chance

How to zoom in multiple objects?

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 3.4k 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.
  • I Offline
    I Offline
    icetbr
    wrote on last edited by
    #1

    Hi, I've seen many example of scaling an image. Does anyone have some reference of zoom in/out multiple objects?

    Thanks

    1 Reply Last reply
    0
    • H Offline
      H Offline
      HuXiKa
      wrote on last edited by
      #2

      I did something like this. I have a custom QGraphiscView, the important parts are:

      @
      class CoordinateSystem : public QGraphicsView{
      ....
      public:
      static double s_X_Scale;
      static double s_Y_Scale;
      signals:
      void updatePartners(double factor);
      protected:
      void wheelEvent(QWheelEvent *event);
      public slots:
      void repaint();
      void rescale(double factor);
      private slots:
      void setXScaleP();
      void setYScaleP();
      void setXScaleM();
      void setYScaleM();
      private:
      QGraphicsScene *m_Scene;
      ...
      }
      @

      The slots and the repaint:

      @void CoordinateSystem::rescale(double factor)
      {
      scale(factor, factor);
      }

      void CoordinateSystem::setXScaleM()
      {
      s_X_Scale = 0.9;
      s_Y_Scale = 1;
      repaint();
      }

      void CoordinateSystem::setYScaleM()
      {
      s_Y_Scale = 0.9;
      s_X_Scale = 1;
      repaint();
      }

      void CoordinateSystem::setXScaleP()
      {
      s_X_Scale = 1.1;
      s_Y_Scale = 1;
      repaint();
      }

      void CoordinateSystem::setYScaleP()
      {
      s_Y_Scale = 1.1;
      s_X_Scale = 1;
      repaint();
      }

      void CoordinateSystem::repaint()
      {
      m_Scene->clear();
      scale(s_X_Scale,s_Y_Scale);

      .....
      }@

      When a mouse wheel event happens:

      @void CoordinateSystem::wheelEvent(QWheelEvent *event)
      {
      double numDegrees = event->delta() / 8.0;
      double numSteps = numDegrees / 15.0;
      double factor = pow(1.125, numSteps);
      scale(factor, factor);
      updatePartners(factor);
      }@

      And the connect:

      @connect(coorsys1, SIGNAL(updatePartners(double)), coorsys2, SLOT(rescale(double)));@

      So in my case, whenever a coordinate system is zoomed in / out (rescaled), every other coordinate system, which is connected to it will also be zoomed in / out (rescaled) by the same ammount.

      Hope this could help you.

      If you can find faults of spelling in the text above, you can keep them.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        icetbr
        wrote on last edited by
        #3

        That's certainly a good start. I will work on that and then post a reply. Thanks

        1 Reply Last reply
        0
        • I Offline
          I Offline
          icetbr
          wrote on last edited by
          #4

          Wait, I have one question. I can't quite see what's happening. Does scale takes care of translating AND scaling? Because QML's Item scale doesn't do that.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            HuXiKa
            wrote on last edited by
            #5

            Sorry, I've slipped over the QML tag, didn't know scale() is different. But there has to be a way to achieve the same behaviour (don't ask me how :) ).

            If you can find faults of spelling in the text above, you can keep them.

            1 Reply Last reply
            0
            • kidproquoK Offline
              kidproquoK Offline
              kidproquo
              wrote on last edited by
              #6

              Could you put the objects you want to scale inside a kind of container and scale that? If I understand the way QML works correctly, that would make all the sub-objects contained in it scale proportionally too.

              Is this the kind of scaling you are referring to, or am I misunderstanding?

              1 Reply Last reply
              0
              • I Offline
                I Offline
                icetbr
                wrote on last edited by
                #7

                Yes, it does scale everything inside, dealing with flickable's contentItem made me forget about that. That's where my problem is, Flickable zoom with dynamic children. I'm making some more tests here, I'll post more information then.

                Thanks for the reminder!

                1 Reply Last reply
                0

                • Login

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