Results 1 to 8 of 8

Thread: QTransform rotate on X axis using QSlider

  1. #1
    Join Date
    Jun 2010
    Posts
    90
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTransform rotate on X axis using QSlider

    Hi,

    I have QGraphicsRectItem on my scene and now I want to rotate this rectangle around x or y axis besides default z axis. I want this to be acheived using QSlider which has a range of 0 to 360. When I slides the slider its value is passed to QTransform as an angle to rorate and respective axis parameter is mentioned in rotate method. This rotates the rectangle but it is not to the angle as it should be, particulary when we are reversing slider it should go back to original state and once slider value is 0 it should be as it before we start i.e. no rotation. But it is giving wiered behviour and not rorating as per expectation.

    Can somebody help me out.

    Thanks in advance


    Manish

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

    Default Re: QTransform rotate on X axis using QSlider

    Please post a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2010
    Posts
    90
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTransform rotate on X axis using QSlider

    Please find the code which I am writing.




    void ShapeSetting::updateItemRotation(qreal r)
    {
    Rectangle *vrect;
    int typ;
    QTransform transform;
    qreal m_rotation_x;
    qreal m_rotation_y;
    qreal m_rotation_z;
    QPointF center;

    qreal old_rot_x = m_rotation_x;
    qreal old_rot_y = m_rotation_y;
    qreal old_rot_z = m_rotation_z;
    m_rotation_x = ui->xSpin->value();
    m_rotation_y = ui->ySpin->value();
    m_rotation_z = ui->zSpin->value();

    transform.translate(50,50);
    transform.rotate(m_rotation_x - old_rot_x,Qt::XAxis);
    transform.rotate(m_rotation_y - old_rot_y,Qt::YAxis);
    transform.rotate(m_rotation_z - old_rot_z,Qt::ZAxis);
    transform.translate(-50,-50);
    switch(typ){
    case 3:
    vrect->transform().reset();
    vrect->setTransform(transform,true);
    break;
    }
    update();
    }

    void ShapeSetting:n_xSlider_valueChanged(int value)
    {
    updateItemRotation(value);
    }

    void ShapeSetting:n_ySlider_valueChanged(int value)
    {
    updateItemRotation(value);
    }

    void ShapeSetting:n_zSlider_valueChanged(int value)
    {
    updateItemRotation(value);
    }

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

    Default Re: QTransform rotate on X axis using QSlider

    This is not a compilable example.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2010
    Posts
    90
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTransform rotate on X axis using QSlider

    Please find attached code



    Manish
    Attached Files Attached Files

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTransform rotate on X axis using QSlider

    The only reason something at all is changing is because you are unsing non initialized variables that give any garabage values they got at definition.
    The fact you are not using the input parameter of updateItemRotation() doesn't help much either.
    Then:
    Qt Code:
    1. QTransform transform;
    2. qreal m_rotation_x; //defining local variables. (the m_ notation suggests this should have a been a member - did you copy this?)
    3. qreal m_rotation_y;
    4. qreal m_rotation_z;
    5. QPointF center;
    6.  
    7. qreal old_rot_x = m_rotation_x; //You are setting the non initialized variables in on other local variables that will die when the function ends.
    8. qreal old_rot_y = m_rotation_y;
    9. qreal old_rot_z = m_rotation_z;
    10. m_rotation_x = ui->xSpin->value();
    11. m_rotation_y = ui->ySpin->value();
    12. m_rotation_z = ui->zSpin->value();
    To copy to clipboard, switch view to plain text mode 

    I am also not quite sure I understand what rotating on more than one axis means on a 2D widget?

    Seems to me you are clueless about what you are doing, or trying to do.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    Default Re: QTransform rotate on X axis using QSlider

    Quote Originally Posted by mvbhavsar View Post
    Please find attached code
    It still doesn't compile.

    In file included from properties.cpp:1:0:
    properties.h:5:26: fatal error: spindelegate.h: Nie ma takiego pliku ani katalogu
    Please post a minimal (i.e. not containing any code irrelevant to the problem) compilable (i.e. something I can run qmake && make on and it builds and runs) example (i.e. not your main project code) reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jun 2010
    Posts
    90
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTransform rotate on X axis using QSlider

    Thanks for response from wysota and high_flyer.
    I have resolved the issue and attaching complete code for reference.

    Also, in reply to high_flyer's remarks, nothing can be done without any intentions and I have firm goals of what I want to achieve, this case was part of one of the very ambitious project. Also, there is much more in rotation about all 3 axis in 2D graphics. It matters when you have different imagination and also if it not much in rotation in 2D then QT would not have given rotation capability about all 3 axis.

    I hope, I am able to clear doubts what I want to achieve through my code.


    Regards

    Manish
    Attached Files Attached Files

Similar Threads

  1. Replies: 4
    Last Post: 1st December 2011, 19:53
  2. Replies: 9
    Last Post: 3rd May 2011, 21:21
  3. Replies: 0
    Last Post: 9th August 2010, 10:46
  4. QTransform rotate and scale order
    By qlands in forum Qt Programming
    Replies: 2
    Last Post: 22nd June 2010, 13:06
  5. QGraphicsView + rotate around axis ?
    By medved6 in forum Qt Programming
    Replies: 4
    Last Post: 25th May 2010, 03:30

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.