1. Intermediate user
Join Date
Feb 2008
Posts
102
Thanks
3
Qt products
Platforms

## 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:
`qreal rectItem::angleForPos(const QPointF &pos){	    qreal angle = acos(pos.x() / distanceToPoint(pos));	if (pos.y() > 0)        angle = -angle;//pi * 2.0 - angle;    return angle;}qreal rectItem::distanceToPoint(const QPointF &pos){	return sqrt(pos.x() * pos.x() + pos.y() * pos.y());} void function_rotating(){QPointF buttonDownPos = mapFromScene(event->buttonDownScenePos(Qt::LeftButton));qreal oldAngle = (180 * angleForPos(buttonDownPos)) / 3.14159265359;qreal newAngle = (180 * angleForPos(event->pos())) / 3.14159265359;newrotation = rotation + oldAngle - newAngle;setMatrix(QMatrix().rotate(newrotation));}`
To copy to clipboard, switch view to plain text mode
Last edited by dreamer; 12th May 2008 at 17:05. Reason: updated contents

2. Beginner
Join Date
Sep 2007
Posts
10
Thanked 1 Time in 1 Post
Qt products
Platforms

## Re: QPointF transformation

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

3. Intermediate user
Join Date
Feb 2008
Posts
102
Thanks
3
Qt products
Platforms

## 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. ## Re: QPointF transformation

What do u want to do ???

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

#### 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.