Oct-06-2024, 02:45 AM
Hi I think I ashed a question like this long ago on the old site, but I have lost my example code from back then.
I am working on a project for designing UIs. Currently using pyqt. One of the features will allow for drawing text and images and being able to rotate them. The problem is I cant remember how to get the rotation working. I know that I need to use translate() then rotate() but all my testing results in the objects not getting placed in the right position. I just want to rotate the object at its center. Basically I want to be able to spin the object like a pinwheel or fidget spinner.
I also remember that for the images you have to re scale them after rotation so they look right.
Can someone give me some example code for this so I can get it working? Thanks.
Here is the last bit of code I tried from the internet:
I am working on a project for designing UIs. Currently using pyqt. One of the features will allow for drawing text and images and being able to rotate them. The problem is I cant remember how to get the rotation working. I know that I need to use translate() then rotate() but all my testing results in the objects not getting placed in the right position. I just want to rotate the object at its center. Basically I want to be able to spin the object like a pinwheel or fidget spinner.
I also remember that for the images you have to re scale them after rotation so they look right.
Can someone give me some example code for this so I can get it working? Thanks.
Here is the last bit of code I tried from the internet:
p = QtGui.QPainter() p.begin() rct = QtCore.QRect(x,y,40,40) center = rct.center() p.save() p.translate(center.x(), center.y()) p.rotate(rotation) p.drawRect(-center.x(), -center.y(), rct.width(), rct.height()) p.restore() p.end()I wish I had not lost my old example code from way back when, but that is what younger me gets for not backing it up.