Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Drawing a straight QGraphicsRectItem when scene rotated (mouse move issue)

$
0
0
Hello, the problem I’m trying to solve relates to drawing a rectangle when the view has been rotated. Basically, I have a scene where I draw a QGraphicsRectItem. The rect item should always be ‘straight’, ie. sides are parallel to the screen sides. When I rotate my view, the rectangle that I draw should always be drawn ‘straight’. I do this by creating my new rect item with the opposite view rotation. This works based on the following code snippet: void SketchScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) { _mousePressPoint = mouseEvent->scenePos();   rectangle = new RectItem(QRectF(_mousePressPoint, _mousePressPoint)); rectangle->setPen( QPen(_penColor, _penSize, _penStyle) ) ; rectangle->setTransformOriginPoint(_mousePressPoint); rectangle->setRotation(-currentViewRotationSum); //fix rotation angle addItem(rectangle) ; } void SketchScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) { QPointF mouseMove = mouseEvent->scenePos(); QRectF newRect(_mousePressPoint, mouseEvent->scenePos());    rectangle->setRect( newRect ); } PROBLEM: when the rotation is greater than 45 degrees, the mouse position with respect to where the upper left corner of the rectangle is drawn is way off. This is very confusing for the user. How can I fix it so that the upper left corner of the rectangle is always following the mouse location when it is moved even when the view is rotated? Thanks in advance for your help, Conrad :)

Viewing all articles
Browse latest Browse all 13965

Trending Articles