Python Forum
[PyQt] Rotake rect, image or text at its center
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Rotake rect, image or text at its center
#1
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:
 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.
Reply
#2
You asked How to rotate images in 2016.
Is that what you forgot?
Reply
#3
Oh wow, thank you. I'll see if I can get this working with PyQt.
Reply
#4
Hi i'm back. I done more work on my project and now I am at a point where I need to add support for images. The problem I am having now is that the images are not completely rotating correctly. What happens is the image will rotate just fine if the location is 0,0 but if I move the image to any other location then when I draw the image after rotation it is not drawing in the proper location. It is completely off to the side somewhere.

p.translate(_w.X + _w.sizeW / 2, _w.Y + _w.sizeH / 2)
# Rotate the painter
p.rotate(_w.rotation)
# Move back to the original position (top-left corner of the pixmap)
p.translate(-(_w.sizeW / 2), -(_w.sizeH / 2))

# Draw the pixmap at the original position with scaling
p.drawPixmap(_w.X, _w.Y, _w.img.scaled(_w.sizeW, _w.sizeH, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation))
Reply
#5
Rotate then translate? What is p?
Reply
#6
Look at this,

https://github.com/EverydayDesignStudio/...-widget.py
Reply
#7
(Oct-22-2024, 01:46 AM)deanhystad Wrote: Rotate then translate? What is p?
p = QtGui.QPainter()
I am using the painter to draw the Pixmap I know that another way to do it would be to use QTransform to create a rotated Pixmap but that also causes the image to shrink and grow and I could not figure out how to fix it, so that is why I am trying it this way but I am having trouble getting the image to draw in the proper location after rotation.
Reply
#8
You can load an image into QLabel
I changed the example from above slightly.


#!/usr/bin/env python3

# Basic rotation widgets

from PyQt5.QtCore import Qt, QByteArray
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import (QGraphicsView, QMainWindow, QApplication, QSlider, 
                            QLabel, QGraphicsScene, QWidget, QGraphicsProxyWidget, 
                            QVBoxLayout)
import sys

class RotatableContainer(QGraphicsView):
    def __init__(self, widget: QWidget, rotation: float):
        super(QGraphicsView, self).__init__()

        scene = QGraphicsScene(self)
        self.setScene(scene)

        self.proxy = QGraphicsProxyWidget()
        self.proxy.setWidget(widget)
        self.proxy.setTransformOriginPoint(self.proxy.boundingRect().center())
        self.proxy.setRotation(rotation)
        scene.addItem(self.proxy)

    def rotate(self, rotation: float):
        self.proxy.setRotation(rotation)


class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)

        self.setWindowTitle("My Awesome Rotating Widget")
        self.setGeometry(0, 0, 600, 400)  #posX, posY, w, h
        
        pic_string = b"iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABHNCSVQICAgIfAhkiAAAIABJREFUeJztnXe8HUXd/98zs3vOrbnplSSEdEhCkS5Ie0AEEQRFERV7Bbso+oj6oCIqiqKCCo8iqPxEmiIdBKRLDy20kHpvkpvcfsqWmd8fM1vOuTc8hDQgfPPa7Dl79py7O9/Pt39nVhhjDG/QNktya1/AG7R16Q0AvCwy/OL3ZzNtj4mMnNrMmCltjJ3cxrgpwxk7dTijprUw/6BZ/P6y323tC91gEm+YgPXTylXLOeDovela3otEgrDHhQAQCIQ9Jtw7I4hFzMxdZnDHFfcipdqKV//y6A0NsB568zG7s/ObdqJ7eR/SMVoIEEIA0u6lfS8cMqQ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PG0KbVQM899xzLFy4kOTR64P+eC4Fu74yrzGG5uZmDjnkkM1yjUEQ0NHRQUdHB+vWrSMI7LIw9Q+MAutjrPrHURyzi0C16iFV/iD1/xLSL3LH0+8D0ToFTzbx0af25I/n3bhZ7juhLeIEVqtVXnjhBZYtW0apVHLhlaQ+Jw8ZEOI4Zvjw4ey11140N2/4hIdNQcl1VKvVtHPo/kfu57AnTyCaWB1sAupe12uAobVBbW+E8A191w7jka6I/c/cfM5fQlssCqinOI4ZGBigVCq5B0GAUoqWlhZaWlo22mnbnPT+k9/OJbPvpDqlCgwuZqUSn2dy3etUG+Q1g6cZuL2VJi35Vtdn2X3B7sycOZN58+ZttnvZagB4rdNbDx/HdUdUCadVslT3EJXNGolfz2skCM+Gfc1Vj8P/PZ/PffjrxLHNBY8ZM4a99957s9zHZs8Evt4ojmOuvPJKvvqVP3Ho9SMovtCIDkWWwIHa1y+DhGcYuK2V5orH4XfM5Ysf+2bKfICVK1dumosfgt4AwAbS1Vdfjed5lMtlTv38+Zzw+GF0P10gzi8w8TJ1qlCGeK1i4Lo2uvvgo88fy+c/+i339LGMNiShtaH0hgnYQLriiivwfT99L4SgUq3wtz98nIsOANMUI7cLkC25xo9cU4xQtt4QrvCJFzdQUPCB2wzvPunCbGXyHEVRxDve8Y6Xld5+JfQGADaQOjs7ufPOO0nW9EuoUCjQ3tHOFVd8jy/P6WCfMT6eZwg8DUW3jEsg8bXtOHpkXcSZC9s47KjTmTp5air1yUIWUkrmz5/PtGnTNuv9vAGAV0hRFLFkyRLa29vp6elJVw1RStHQ0EB7Rzt3P3QnnZ3PUdB9EFcJ1TCGj5zJPrvtz5TJU6hUKkRRhFIK3/cZPXo0kyZNYuLEiVssCnoDANs4/X/n7EPPhOkj4QAAAABJRU5ErkJggg=="

        # Widget you want to rotate
        label = QLabel(alignment=Qt.AlignCenter)
        
        ### if you wanto use an image from path uncomment this and comment line 44 and 45
        #pix = QPixmap("/path/to/image")
        
        pix = QPixmap()
        pix.loadFromData(QByteArray.fromBase64(pic_string))
        
        label.setPixmap(pix)
        # Container you place the widget in
        container = RotatableContainer(widget=label, rotation=0)

        # Create slider and connect to the rotate method in the container
        slider = QSlider(minimum=0, maximum=359, orientation=Qt.Horizontal)
        slider.valueChanged.connect(container.rotate)

        label_text = QLabel("{}°".format(slider.value()), alignment=Qt.AlignCenter)
        slider.valueChanged.connect(lambda value: label_text.setText("{}°".format(slider.value())))

        # Display the widgets
        w = QWidget()
        lay = QVBoxLayout(w)
        lay.addWidget(container)
        lay.addWidget(slider)
        lay.addWidget(label_text)
        w.resize(640, 480)

        self.setCentralWidget(w)
        self.show()


app = QApplication([])  # Holds the event loop
window = MainWindow()
app.exec_()
Reply
#9
rotate, scale, shear and translate alter the world transform. When drawing lines or shapes, the world transform controls how the lines or shapes are drawn.
There effect is cumulative, so if you rotate and then translate the effect is different that translating and then rotating.
app = QtWidgets.QApplication()
pixmap = QtGui.QPixmap(100, 100)

p = QtGui.QPainter()
p.begin(pixmap)
print("Origin", p.worldTransform())
p.translate(4, 0)
print("Translate(4, 0)", p.worldTransform())
p.rotate(90)
print("Rotate(90)", p.worldTransform())
p.translate(-4, 0)
print("Traslate(4, 0)", p.worldTransform())
p.end()
Output:
Origin PySide6.QtGui.QTransform(1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000) Translate(4, 0) PySide6.QtGui.QTransform(1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 4.000000, 0.000000, 1.000000) Rotate(90) PySide6.QtGui.QTransform(0.000000, 1.000000, 0.000000, -1.000000, 0.000000, 0.000000, 4.000000, 0.000000, 1.000000) Traslate(4, 0) PySide6.QtGui.QTransform(0.000000, 1.000000, 0.000000, -1.000000, 0.000000, 0.000000, 4.000000, -4.000000, 1.000000)
Notice that the first translate(4, 0) moves the worldTransfom origin to (4, 0), but the second translate(4, 0) moves the worldTransform origin to (4, -4). The rotate(90) rotated the coordinate system so that translating in the x direction now becomes a translation in the -z direction.

The easiest way to return to the start is use save() and restore().
from qtpy import QtGui, QtWidgets

app = QtWidgets.QApplication()
pixmap = QtGui.QPixmap(100, 100)

p = QtGui.QPainter()
p.begin(pixmap)
print("Origin", p.worldTransform())
p.save()
p.translate(4, 0)
print("Translate(4, 0)", p.worldTransform())
p.rotate(90)
print("Rotate(90)", p.worldTransform())
p.translate(-4, 0)
print("Traslate(4, 0)", p.worldTransform())
p.restore()
print("Restore()", p.worldTransform())

p.end()
Output:
Origin PySide6.QtGui.QTransform(1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000) Translate(4, 0) PySide6.QtGui.QTransform(1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 4.000000, 0.000000, 1.000000) Rotate(90) PySide6.QtGui.QTransform(0.000000, 1.000000, 0.000000, -1.000000, 0.000000, 0.000000, 4.000000, 0.000000, 1.000000) Traslate(4, 0) PySide6.QtGui.QTransform(0.000000, 1.000000, 0.000000, -1.000000, 0.000000, 0.000000, 4.000000, -4.000000, 1.000000) Restore() PySide6.QtGui.QTransform(1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000)
Saving the transform before doing any translations and rotations allows returning to the original transform.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGTK] How to center text on multi-line buttons? Lomax 3 5,011 Jan-23-2021, 03:23 PM
Last Post: Lomax
Photo Tkinter TEXT background image _ShevaKadu 5 9,161 Nov-02-2020, 10:34 AM
Last Post: joe_momma
  Spacing Between two labels are very far and Top label is not in Center using Tkinter barry76 2 7,992 Jul-30-2019, 10:49 AM
Last Post: wuf
  how to insert image into Text widget Tkinter atlass218 5 10,854 Apr-17-2019, 05:28 AM
Last Post: atlass218
  [Tkinter] How do I center this text in tkinter? ejected 4 65,636 Mar-29-2019, 10:35 PM
Last Post: woooee
  the alternate keyboard commands / center command Luke_Drillbrain 3 4,570 Apr-30-2017, 03:30 PM
Last Post: buran
  PyQt4 text edit align text center iFunKtion 3 15,647 Mar-10-2017, 06:02 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020