PyQt5 blurpicker example
-
Hello, does someone has the Python (PyQt5) version of the BlurPicker example from the Qt Crator 5. Itried to convert it to Python, but I cant get the right solution . This is my code:
import math from PyQt5.QtCore import (pyqtSignal,QEasingCurve, QPointF, QPropertyAnimation, QAbstractAnimation, QRect, QRectF, QState, QStateMachine, Qt, QTimer) from PyQt5.QtGui import QPixmap, QPainter from PyQt5.QtWidgets import (QApplication, QGraphicsScene, QGraphicsView,QGraphicsItem, QGraphicsWidget, QFrame) class BlurPicker(QGraphicsView): def __init__(self, parent=None): super(BlurPicker, self).__init__(parent) self.m_index = 0.0 self.scene = QGraphicsScene() self.m_icons = [] self.names = [] self.m_animation = QPropertyAnimation(self,b'index') print("bb") #self.setScene(self.scene) self.setupScene() self.setIndex(0) self.m_animation.setDuration(400) self.m_animation.setEasingCurve(QEasingCurve.InOutSine) self.setRenderHint(QPainter.Antialiasing) self.setFrameStyle(QFrame.NoFrame) def index(self): print("aa") return self.m_index def setIndex(self,index): self.m_index = index self.baseline = 0 print(self.m_icons.count(self)) for i in range(self.m_icons.count(self)): print("ii") icon = QGraphicsItem() self.a = ((i + self.m_index)*2*math.pi/ self.m_icons.count(self)) xs = 170 * math.sin(self.a) ys = 170 * math.cos(self.a) pos = QPointF(xs, ys) icon.setPos(pos) self.baseline = math.max(self.baseline, ys) icon.graphicsEffect().setBaseLine(self.baseline) self.scene.update() def setupScene(self): self.scene.setSceneRect(-300, -200, 600, 460) names = [] names.append('green_box.png') names.append('green_box.png') names.append('green_box.png') names.append('green_box.png') names.append('green_box.png') names.append('green_box.png') names.append('green_box.png') print(names) for i in names: pixmap = QPixmap(names) icon = self.scene.addPixmap(pixmap) icon.setZValue(1) self.m_icons.append(icon) self.scene.addItem(icon) def keyPressEvent(self, e): delta = 0 if e.key() == Qt.Key_Left: delta = -1 elif e.key() == Qt.Key_Right: delta = 1 else: pass if self.m_animation.state() == QAbstractAnimation.Stopped and delta: self.m_animation.setEndValue(self.m_index + delta) self.m_animation.star() e.accept() if __name__== '__main__': import sys app = QApplication(sys.argv) picker = BlurPicker() picker.setWindowTitle("Picker") picker.resize(640, 480) picker.show() sys.exit(app.exec_())
-
@alekssandrap said in PyQt5 blurpicker example:
What do you exactly mean withbut I cant get the right solution .
?
Any errors, any crashes, other unexpected behaviour?
-
I only am getting an empty window as an output. And this error: QPropertyAnimation: you're trying to animate a non-existing property index of your QObject
-
Did not go through all the code but
for i in names: pixmap = QPixmap(names) icon = self.scene.addPixmap(pixmap) icon.setZValue(1) self.m_icons.append(icon) self.scene.addItem(icon)
as
names
is a list and you iterate through this list you should usei
instead ofnames
inpixmap = ...
also there seems to be a typo
self.m_animation.star()
should beself.m_animation.start()
-
Thank you! I didnt noticed that. I did correct this mistakes, but still getting the same error:( and empty window :/