Results 1 to 4 of 4

Thread: QPointF transformation

  1. #1
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QPointF transformation

    Hi.
    When we read a point from a QGraphicsItem, it refers to the (0,0) coordinate system of the same item.

    How can i map that point , so it refers to an other (x,y) point{not (0,0)} of the same item????

    In general:
    How can i obtain a generic rappresentation on the mouse moving in degree, that is valid both for the case in which the item has the (0,0) local coordinate in its centre or in other parts(like the topleft corner)?? thanks

    I found this code that is valid if and only if the item has the (0,0) local coordinate in its centre.

    Qt Code:
    1. qreal rectItem::angleForPos(const QPointF &pos){
    2. qreal angle = acos(pos.x() / distanceToPoint(pos));
    3. if (pos.y() > 0)
    4. angle = -angle;//pi * 2.0 - angle;
    5. return angle;
    6. }
    7. qreal rectItem::distanceToPoint(const QPointF &pos){
    8. return sqrt(pos.x() * pos.x() + pos.y() * pos.y());
    9. }
    10.  
    11. void function_rotating(){
    12. QPointF buttonDownPos = mapFromScene(event->buttonDownScenePos(Qt::LeftButton));
    13. qreal oldAngle = (180 * angleForPos(buttonDownPos)) / 3.14159265359;
    14. qreal newAngle = (180 * angleForPos(event->pos())) / 3.14159265359;
    15. newrotation = rotation + oldAngle - newAngle;
    16. setMatrix(QMatrix().rotate(newrotation));
    17. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by dreamer; 12th May 2008 at 17:05. Reason: updated contents

  2. #2
    Join Date
    Sep 2007
    Posts
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPointF transformation

    Take a look at the :
    int QPoint::manhattanLength ()

  3. #3
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: QPointF transformation

    I'm working with QPointF Object and not with QPoint............
    Isn't there any "map" function that give me this behaviour?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPointF transformation

    What do u want to do ???

    I guess u take a look at scenePos() . Hope it will help u

Similar Threads

  1. how can QPixmap transformation to QBitmap faster
    By duduqq in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2008, 04:44
  2. QGraphicsView coordinates transformation
    By mtribaldos in forum Newbie
    Replies: 1
    Last Post: 6th February 2008, 17:44

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.