Results 1 to 12 of 12

Thread: Rotation on Qframe

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2007
    Posts
    22
    Thanks
    1

    Default Rotation on Qframe

    Hello,

    I am using QT3 and am not so much fimiliar with the qt-programming. I have to make a rotation function on a qframe widget. I have my own rectangle class. The follow is what i have made but its not done correctly. Can someone please take a look at the code and give me some suggestion?

    Qt Code:
    1. double View::Rotate(double a_dRotate)
    2. {
    3. MyRect m_Dev;
    4. MyRect m_Form;
    5. FRect m_Window;
    6.  
    7. int iWidth = m_Dev.Width();
    8.  
    9. QRect R = rect();
    10. m_Form.Rect( R.left(), R.top(), R.right(), R.bottom() );
    11.  
    12. m_Dev.Width(m_Dev.Width() * a_dRotate);
    13.  
    14. if (m_Dev.Width() > 12000)
    15. m_Dev.Width(12000);
    16.  
    17. if (m_Dev.Width() > 5000000)
    18. m_Dev.Width(5000000);
    19.  
    20. if (m_Dev.Width() < 50)
    21. m_Dev.Width(50);
    22.  
    23.  
    24. m_Dev.Height( (double)m_Dev.Width() / ((double)m_Window.Width() / (double)m_Window.Height()) );
    25. return ((double)m_Dev.Width() / (double)iWidth);
    26. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotation on Qframe

    What exactly are you trying to rotate? Have you seen QWMatrix::rotate()?
    Last edited by wysota; 1st April 2008 at 11:02.

  3. #3
    Join Date
    Sep 2007
    Posts
    22
    Thanks
    1

    Default Re: Rotation on Qframe

    Quote Originally Posted by wysota View Post
    What exactly are you trying to rotate? Have you seen QWorldMatrix::rotate()?
    A rectangle inside a qframe. I have seen QWorldMatrix but can i use it with QRECT?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotation on Qframe

    Take a look at QWMatrix::mapRect().

  5. #5
    Join Date
    Sep 2007
    Posts
    22
    Thanks
    1

    Default Re: Rotation on Qframe

    Quote Originally Posted by wysota View Post
    Take a look at QWMatrix::mapRect().
    I have changed my code as follows but it doesnt work at all.
    Qt Code:
    1. MyRect m_Dev;
    2. MyRect m_Form;
    3. QRect View = rect();
    4. QWMatrix m;
    5.  
    6. int x = -( m_Dev.Left() - ((View.left() + View.right()) ) );
    7. int y = -( m_Dev.Top() - ((View.top() + View.bottom()) ) );
    8. m.mapRect(View);
    9. m.rotate( -45.0 );
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotation on Qframe

    Because it doesn't work that way.

    Qt Code:
    1. QWMatrix m;
    2. m.rotate(-45);
    3. QRect newRect = m.mapRect(rect());
    To copy to clipboard, switch view to plain text mode 

    Look closely what each method does and returns.

  7. #7
    Join Date
    Sep 2007
    Posts
    22
    Thanks
    1

    Default Re: Rotation on Qframe

    Quote Originally Posted by wysota View Post
    Because it doesn't work that way.

    Qt Code:
    1. QWMatrix m;
    2. m.rotate(-45);
    3. QRect newRect = m.mapRect(rect());
    To copy to clipboard, switch view to plain text mode 

    Look closely what each method does and returns.
    Yep thnx alot. But i see stil some mis calculation in my methods i have one main class which has these two functions and it is XView: QFrame -

    Qt Code:
    1. double XView::Rotate(double a_dRotate)
    2. {
    3. QWMatrix m;
    4. m.rotate(22);
    5. QRect newRect = m.mapRect(rect());
    6. return a_dRotate;
    7. }
    8.  
    9. void XView::Rotate(double a_dRotate, double x, double y)
    10. {
    11. double rotateView = Rotate(a_dRotate);
    12.  
    13. x *= rotateView;
    14. y *= rotateView;
    15. }
    To copy to clipboard, switch view to plain text mode 
    In my other class which is View: XView, i have a slot which should do the rotation and it is as follows:

    Qt Code:
    1. void View::SlotRotate()
    2. {
    3.  
    4. QRect View = rect();
    5.  
    6. //in this place the rectangle is calculated,
    7. int x = -( m_Dev.Left() - ((View.left() + View.right()) ) );
    8. int y = -( m_Dev.Top() - ((View.top() + View.bottom()) ) );
    9.  
    10.  
    11. Rotate(22, x, y);
    12. }
    To copy to clipboard, switch view to plain text mode 

    I see that its not working properly.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotation on Qframe

    Quote Originally Posted by Pharell View Post
    Qt Code:
    1. double XView::Rotate(double a_dRotate)
    2. {
    3. QWMatrix m;
    4. m.rotate(22);
    5. QRect newRect = m.mapRect(rect());
    6. return a_dRotate;
    7. }
    To copy to clipboard, switch view to plain text mode 
    This code does exactly nothing. You calculate a rectangle based on some other rectangle and return the argument the method was given as a parameter. If you pass it 4.0573 it will return 4.0573, etc.


    In my other class which is View: XView, i have a slot which should do the rotation and it is as follows:

    Qt Code:
    1. void View::SlotRotate()
    2. {
    3.  
    4. QRect View = rect();
    5.  
    6. //in this place the rectangle is calculated,
    7. int x = -( m_Dev.Left() - ((View.left() + View.right()) ) );
    8. int y = -( m_Dev.Top() - ((View.top() + View.bottom()) ) );
    9.  
    10.  
    11. Rotate(22, x, y);
    12. }
    To copy to clipboard, switch view to plain text mode 

    I see that its not working properly.
    What would you like the code to do? Because currently your Rotate() function is meaningless, it's a no-op. SlotRotate() is also meaningless - you create a bunch of variables which you never use.

  9. #9
    Join Date
    Sep 2007
    Posts
    22
    Thanks
    1

    Default Re: Rotation on Qframe

    Hello ppls,
    I am still fighting with this rotation problem. When i debug i see that the coordinates are changing but the view is not changing. The qrect has normal (x1= 0, y1=0, x2 = 511, y2 = 469) after setting the rotate(180.0), these coordinates changes to = (x1= -511, y1 = -469, x2=0, y2= 0)

    Qt Code:
    1. QWMatrix m;
    2. QRect R;
    3. m_Form.Rect( R.left(), R.top(), R.right(), R.bottom() );
    4. m.rotate(180.0);
    5. R = m.mapRect(rect());
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotation on Qframe

    What do you do with "R" afterwards?

  11. #11
    Join Date
    Sep 2007
    Posts
    22
    Thanks
    1

    Default Re: Rotation on Qframe

    Quote Originally Posted by wysota View Post
    What do you do with "R" afterwards?
    notting (i am really confused with it) i have send u the code of zoom yesterday and that code works fine that way. I call this function(Above code) with a slot.

Similar Threads

  1. Using a QFrame as a color selection indicator
    By KShots in forum Qt Tools
    Replies: 8
    Last Post: 14th June 2011, 23:55
  2. scrollbar in a qframe
    By davea402 in forum Qt Programming
    Replies: 2
    Last Post: 21st February 2008, 18:26
  3. how to determine geometry of a QFrame
    By impeteperry in forum Qt Programming
    Replies: 3
    Last Post: 10th October 2007, 19:07
  4. QFrame inserting text
    By Pharell in forum Qt Programming
    Replies: 9
    Last Post: 8th October 2007, 09:55
  5. QFrame subclass does not reparent
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2006, 22:15

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.