1. Beginner
Join Date
Nov 2019
Posts
6
Qt products
Platforms

## Rotate GraphicsObjects

Hi,

i am able to paint/add i.e. rectangles as graphicsobject in a scene/graphicsview.

now i wanted to rotate them and i tried with transform.rotate() and it works with all items or a single item.

but now i want to rotate 4 of the rectangles combined as a cube (without botton & top).

how can i archieve this?

regards

2. ## Re: Rotate GraphicsObjects

Create a QGraphicsItemGroup and add your rectangles to it. You can then transform the group in the same way you transform a single object.

3. Beginner
Join Date
Nov 2019
Posts
6
Qt products
Platforms

## Re: Rotate GraphicsObjects

Ok, now i can group the items, but ...

... i think it is more a mathematical problem ...

i have to arrange the items in a square (from top-view).

but the items have to be rotated to do this, but the rotation point is not in 2D.

Cube01.png
Last edited by FlyingEagle; 20th November 2019 at 12:51.

4. ## Re: Rotate GraphicsObjects

Qt Graphics / View is 2D only, so you are going to have to define your "rectangles" as parallelograms. You will have to transform rectangles in 3D, then project the rectangle coordinates onto the 2D plane, which will yield parallelograms.

5. Beginner
Join Date
Nov 2019
Posts
6
Qt products
Platforms

## Re: Rotate GraphicsObjects

Originally Posted by d_stranz
You will have to transform rectangles in 3D
And how can I archive this?

6. ## Re: Rotate GraphicsObjects

Google is your friend. Try "3d graphics transformation". You may be able to find a third-party library to do this. But basically, you must build your model as a 3D object, transform it to the desired orientation, then project the 3D x-y-z coordinates onto a 2D x-y plane.

7. Beginner
Join Date
Mar 2010
Posts
5
Thanked 1 Time in 1 Post
Qt products
Platforms

## Re: Rotate GraphicsObjects

There is a section on 3D rotations about an arbitrary axis in my book "Computer Graphics Programming in C++/Qt", available as e-book and as paperback on Amazon/Kindle. Even without buying the book, you can find the C++/Qt code from https://github.com/LAmmeraal/. Just look at the file edit3d.pro to see which source files are relevant. The files rota3d.cpp and rota3d.h deal with rotations. If you use Windows, you can immediately try the executable file edit3d.exe, using the Edit menu. The above book explains all this in more detail.
Best wishes,
Leen Ammeraal
Last edited by lamm; 26th November 2019 at 18:38.

8. ## The following user says thank you to lamm for this useful post:

d_stranz (26th November 2019)

9. ## Re: Rotate GraphicsObjects

Computer Graphics Programming in C++/Qt
Thanks! You just sold a book.

10. Beginner
Join Date
Mar 2010
Posts
5
Thanked 1 Time in 1 Post
Qt products
Platforms

## Re: Rotate GraphicsObjects

Originally Posted by d_stranz
Thanks! You just sold a book.
If it is Okay or better, please tell others; if not, tell me.

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