1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QLabel, QSpinBox, QGridLayout)
from PyQt5.QtGui import QPixmap, QTransform, QPainter, QPen
from PyQt5.QtCore import Qt
class CameraWidget(QWidget):
def __init__(self, parent=None):
super(CameraWidget, self).__init__(parent)
self.im = QPixmap("./23794_50.png")
self.angle_min = -45
self.angle_max = 45
self.angle = 0
self.diag = (self.im.width()**2 + self.im.height()**2)**0.5
self.label = QLabel()
self.label.setFixedSize(self.diag, self.diag)
self.label.setAlignment(Qt.AlignCenter)
self.label.setPixmap(self.im)
self.spin = QSpinBox()
self.spin.setMinimum(self.angle_min)
self.spin.setMaximum(self.angle_max)
self.spin.valueChanged.connect(self.update)
self.grid = QGridLayout()
self.grid.addWidget(self.label, 0, 1)
self.grid.addWidget(self.spin, 1, 1)
self.setLayout(self.grid)
self.update()
def update(self):
pixmap = self.im
self.rotation = self.spin.value()
transform = QTransform().rotate(self.rotation)
pixmap = pixmap.transformed(transform, Qt.SmoothTransformation)
self.label.setPixmap(pixmap)
def paintEvent(self, event):
painter = QPainter(self)
pen = QPen()
pen.setWidth(3)
pen.setColor(Qt.blue)
painter.setPen(pen)
painter.drawEllipse(int(self.diag/2) - 11, int(self.diag/2) - 25, self.diag, self.diag)
if __name__ == '__main__':
app = QApplication(sys.argv)
cam = CameraWidget()
cam.setWindowTitle("PyQT show image")
cam.show()
sys.exit(app.exec_()) |
Partager