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. QGraphicsView 90 degree Rotation

QGraphicsView 90 degree Rotation

Scheduled Pinned Locked Moved Unsolved General and Desktop
25 Posts 4 Posters 11.0k 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.
  • K Offline
    K Offline
    keksi venksi
    wrote on 22 May 2017, 17:31 last edited by keksi venksi
    #9

    I tried to add image in my post but i cant .
    Can you help me on it

    ? 1 Reply Last reply 22 May 2017, 17:52
    0
    • ? A Former User
      22 May 2017, 15:57

      Sry, I think I don't understand exactly what you want to do. Maybe you can draw a few pictures to help my imagination :)

      K Offline
      K Offline
      keksi venksi
      wrote on 22 May 2017, 17:42 last edited by keksi venksi
      #10

      @Wieland

      X Mode

      **-----------------------------|

      -----------------------------**
      Width

      This is how I locate my graphicsview at initial stage

      Im achieving zooming through wheel event .

      I have currentZoomingWidth level if the delta is +ve then i will increase the currentZoomingWidth level and if it is -ve then i will decrease the currentZoomingWidth
      So finally i find the width to expand (currentZoomingWidth )

      wheelvent()
      {
      fitInVieW(0,0,currentZoomingWidth ,view().geometry().height())
      }
      So zooming is achieved through fitInView()

      Y MODE
      | |
      | |
      | |
      | |
      | | Height
      | |
      | |

      Width

      Like same case im calculating the currentZoomingWidth depending upon the delta and applying it to fitInView() height

      wheelvent()
      {
      fitInVieW(0,0 ,view().geometry().width(),currentZoomingWidth)
      }

      In X mode i apply the calculated zoom factor to width and in Y mode I apply it to the height

      My problem is In X mode the fit in view works fine but in Y mode it works weird

      1 Reply Last reply
      0
      • K keksi venksi
        22 May 2017, 17:31

        I tried to add image in my post but i cant .
        Can you help me on it

        ? Offline
        ? Offline
        A Former User
        wrote on 22 May 2017, 17:52 last edited by
        #11

        @keksi-venksi said in QGraphicsView 90 degree Rotation:

        I tried to add image in my post but i cant .
        Can you help me on it

        Hi! The image-upload feature on our forum is broken, you might see the picture but other users don't. Please upload your image to a image hoster of your choice (e.g. postimage.org) and embed the pic here with the following markup: ![alternate text](image-url). See also How to insert image on this forum and Hitchhiker's Visual Guide to the Qt Forum.

        K 1 Reply Last reply 22 May 2017, 19:01
        1
        • ? A Former User
          22 May 2017, 17:52

          @keksi-venksi said in QGraphicsView 90 degree Rotation:

          I tried to add image in my post but i cant .
          Can you help me on it

          Hi! The image-upload feature on our forum is broken, you might see the picture but other users don't. Please upload your image to a image hoster of your choice (e.g. postimage.org) and embed the pic here with the following markup: ![alternate text](image-url). See also How to insert image on this forum and Hitchhiker's Visual Guide to the Qt Forum.

          K Offline
          K Offline
          keksi venksi
          wrote on 22 May 2017, 19:01 last edited by keksi venksi
          #12

          @Wieland

          I have explained my query in my previous post . Please give your suggestions
          graphicsview

          Any how i have added the image here .This is how my graphicsview rotated .
          Now i wanna apply zooming functionality using fitinview in this 90 degree rotated graphicsview .

          This is how Y Mode looks

          K 1 Reply Last reply 22 May 2017, 21:11
          0
          • K keksi venksi
            22 May 2017, 19:01

            @Wieland

            I have explained my query in my previous post . Please give your suggestions
            graphicsview

            Any how i have added the image here .This is how my graphicsview rotated .
            Now i wanna apply zooming functionality using fitinview in this 90 degree rotated graphicsview .

            This is how Y Mode looks

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 22 May 2017, 21:11 last edited by
            #13

            Use two QTransform objects - one for rotation and one for scaling, then multiply them in the proper order (the order of multiplication matters as scaling and rotation don't commute). After that apply your transform to whatever you need.

            Read and abide by the Qt Code of Conduct

            K 1 Reply Last reply 22 May 2017, 21:32
            0
            • K kshegunov
              22 May 2017, 21:11

              Use two QTransform objects - one for rotation and one for scaling, then multiply them in the proper order (the order of multiplication matters as scaling and rotation don't commute). After that apply your transform to whatever you need.

              K Offline
              K Offline
              keksi venksi
              wrote on 22 May 2017, 21:32 last edited by
              #14

              @kshegunov
              Thanks for your reply .
              Can you give some example code .

              K 1 Reply Last reply 22 May 2017, 21:35
              0
              • K keksi venksi
                22 May 2017, 21:32

                @kshegunov
                Thanks for your reply .
                Can you give some example code .

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 22 May 2017, 21:35 last edited by
                #15
                QTransform rotation;
                rotation.rotate(90);
                
                QTransform scaling;
                scaling.scale(0.5, 1);
                
                setTransform(rotation * scaling);
                // Or
                QVector2D vector;
                vector = rotation * scaling * vector;
                

                Modify according to your needs.

                Read and abide by the Qt Code of Conduct

                K 1 Reply Last reply 22 May 2017, 21:46
                1
                • K kshegunov
                  22 May 2017, 21:35
                  QTransform rotation;
                  rotation.rotate(90);
                  
                  QTransform scaling;
                  scaling.scale(0.5, 1);
                  
                  setTransform(rotation * scaling);
                  // Or
                  QVector2D vector;
                  vector = rotation * scaling * vector;
                  

                  Modify according to your needs.

                  K Offline
                  K Offline
                  keksi venksi
                  wrote on 22 May 2017, 21:46 last edited by keksi venksi
                  #16

                  @kshegunov

                  Thanks for your reply .

                  In my case I dont want to use scale to zoom

                  I wish to use fitInView() to achieve zoom.

                  In short note after applying transform (rotate 90 degree) fitInView() does not works fine . I want fitInView() to do zoom

                  K 1 Reply Last reply 23 May 2017, 06:47
                  0
                  • K keksi venksi
                    22 May 2017, 21:46

                    @kshegunov

                    Thanks for your reply .

                    In my case I dont want to use scale to zoom

                    I wish to use fitInView() to achieve zoom.

                    In short note after applying transform (rotate 90 degree) fitInView() does not works fine . I want fitInView() to do zoom

                    K Offline
                    K Offline
                    keksi venksi
                    wrote on 23 May 2017, 06:47 last edited by keksi venksi
                    #17

                    @keksi-venksi

                    Can any one help me on it .
                    Helps are really appreciable

                    K 1 Reply Last reply 23 May 2017, 14:57
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on 23 May 2017, 14:51 last edited by
                      #18

                      customgraphicsview.h

                      #ifndef CUSTOMGRAPHICSVIEW_H
                      #define CUSTOMGRAPHICSVIEW_H
                      
                      #include <QGraphicsView>
                      
                      class CustomGraphicsView : public QGraphicsView
                      {
                          Q_OBJECT
                      public:
                          enum class Mode
                          {
                              x,
                              y
                          };
                      
                          explicit CustomGraphicsView(QWidget *parent = nullptr);
                          void reset();
                          void fit();
                          void setMode(Mode mode);
                      
                      protected:
                          void wheelEvent(QWheelEvent* event) override;
                      
                      private:
                          void updateTransform();
                          Mode m_mode = Mode::x;
                          double m_scale = 1.0;
                      };
                      
                      #endif // CUSTOMGRAPHICSVIEW_H
                      

                      customgraphicsview.cpp

                      #include "customgraphicsview.h"
                      #include <QBrush>
                      #include <QColor>
                      #include <QWheelEvent>
                      #include <QDebug>
                      
                      CustomGraphicsView::CustomGraphicsView(QWidget *parent)
                          : QGraphicsView(parent)
                      {
                          setBackgroundBrush(QBrush(QColor("grey")));
                      }
                      
                      void CustomGraphicsView::reset()
                      {
                          m_mode = Mode::x;
                          m_scale = 1.0;
                          updateTransform();
                      }
                      
                      void CustomGraphicsView::fit()
                      {
                          auto const r = scene()->itemsBoundingRect();
                          switch (m_mode) {
                          case Mode::x: {
                              double f1 = width() / (r.width() + 2);
                              double f2 = height() / (r.height() + 2);
                              m_scale = qMin(f1,f2);
                              updateTransform();
                              break;
                          }
                          case Mode::y: {
                              double f1 = height() / (r.width() + 2);
                              double f2 = width() / (r.height() + 2);
                              m_scale = qMin(f1,f2);
                              updateTransform();
                              break;
                          }
                          }
                      }
                      
                      void CustomGraphicsView::setMode(CustomGraphicsView::Mode mode)
                      {
                          if (m_mode == mode)
                              return;
                          m_mode = mode;
                          updateTransform();
                      }
                      
                      void CustomGraphicsView::wheelEvent(QWheelEvent *event)
                      {
                          auto const delta = (event->delta() <0.0) ? -1.0 : 1.0;
                          m_scale += 0.1 * delta;
                          updateTransform();
                      }
                      
                      void CustomGraphicsView::updateTransform()
                      {
                          QTransform t;
                          if (m_mode == Mode::y)
                              t.rotate(90);
                          t.scale(m_scale, m_scale);
                          setTransform(t);
                      }
                      
                      1 Reply Last reply
                      1
                      • K keksi venksi
                        23 May 2017, 06:47

                        @keksi-venksi

                        Can any one help me on it .
                        Helps are really appreciable

                        K Offline
                        K Offline
                        keksi venksi
                        wrote on 23 May 2017, 14:57 last edited by
                        #19

                        @keksi-venksi

                        I would like to continue with this thread

                        in the normal mode im using view->fitInView(rect.x(),0,rect.width(),30)

                        in the 90 degree rotated mode im using view->fitInView(0,rect.y(),30,rect.height())

                        I have tried with different combinations of fitInView for 90 degree rotataion Nothing works

                        Can any one suggest me the coordinates for the fitInView() for the rotated view

                        Help me on it

                        ? 1 Reply Last reply 23 May 2017, 14:59
                        0
                        • K keksi venksi
                          23 May 2017, 14:57

                          @keksi-venksi

                          I would like to continue with this thread

                          in the normal mode im using view->fitInView(rect.x(),0,rect.width(),30)

                          in the 90 degree rotated mode im using view->fitInView(0,rect.y(),30,rect.height())

                          I have tried with different combinations of fitInView for 90 degree rotataion Nothing works

                          Can any one suggest me the coordinates for the fitInView() for the rotated view

                          Help me on it

                          ? Offline
                          ? Offline
                          A Former User
                          wrote on 23 May 2017, 14:59 last edited by
                          #20

                          @keksi-venksi Please try the code above that I just posted. If I understood you right, then it should meet your requirements :)

                          K 1 Reply Last reply 23 May 2017, 15:03
                          0
                          • ? A Former User
                            23 May 2017, 14:59

                            @keksi-venksi Please try the code above that I just posted. If I understood you right, then it should meet your requirements :)

                            K Offline
                            K Offline
                            keksi venksi
                            wrote on 23 May 2017, 15:03 last edited by
                            #21

                            @Wieland
                            @Wieland

                            Thanks for your reply

                            I am using fitInView in many places in my project to work stable . So I would like to get some suggestions for fitInView() coordinates

                            ? 1 Reply Last reply 23 May 2017, 21:16
                            0
                            • K keksi venksi
                              23 May 2017, 15:03

                              @Wieland
                              @Wieland

                              Thanks for your reply

                              I am using fitInView in many places in my project to work stable . So I would like to get some suggestions for fitInView() coordinates

                              ? Offline
                              ? Offline
                              A Former User
                              wrote on 23 May 2017, 21:16 last edited by A Former User
                              #22

                              @keksi-venksi said in QGraphicsView 90 degree Rotation:

                              I am using fitInView in many places in my project to work stable . So I would like to get some suggestions for fitInView() coordinates

                              This is probably my last posting here because I think I can't help you. Have you seen my code above? The fit() function? It does just what you want, look:

                              1 Reply Last reply
                              1
                              • K Offline
                                K Offline
                                keksi venksi
                                wrote on 24 May 2017, 07:15 last edited by keksi venksi
                                #23

                                Hi

                                Thanks for your reply

                                In this example in fit method you are trying it to fit the view in the frame when we click a button but my case i have used fitInView() while zooming .So it should adjust the view with the zooming delta

                                So when ever we zoom fitInView() should be adjusted accordingly to the scene and update the scene as well

                                K 1 Reply Last reply 24 May 2017, 22:09
                                0
                                • K keksi venksi
                                  24 May 2017, 07:15

                                  Hi

                                  Thanks for your reply

                                  In this example in fit method you are trying it to fit the view in the frame when we click a button but my case i have used fitInView() while zooming .So it should adjust the view with the zooming delta

                                  So when ever we zoom fitInView() should be adjusted accordingly to the scene and update the scene as well

                                  K Offline
                                  K Offline
                                  keksi venksi
                                  wrote on 24 May 2017, 22:09 last edited by
                                  #24

                                  @keksi-venksi

                                  To All The issue has been fixed

                                  what i did was simple

                                  X mode fitinview(0,0,calcValue,viewRectHeight)

                                  Y Mode fitinview(0,0,viewRectWidth,calcValue) ; rotate(90)

                                  After calling fitinview again im calling rotate of 90 degree

                                  1 Reply Last reply
                                  0
                                  • EddyE Offline
                                    EddyE Offline
                                    Eddy
                                    wrote on 25 May 2017, 05:16 last edited by
                                    #25

                                    @keksi-venksi
                                    Could you please mark this topic as solved then. Others will find it easier if they have similar questions.

                                    Qt Certified Specialist
                                    www.edalsolutions.be

                                    1 Reply Last reply
                                    0

                                    18/25

                                    23 May 2017, 14:51

                                    • Login

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