Python Forum
[PyQt] PyQt5 blurpicker example
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] PyQt5 blurpicker example
#1
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 (QEasingCurve, QPointF, QPropertyAnimation, QAbstractAnimation, Qt)
from PyQt5.QtGui import QPixmap, QPainter
from PyQt5.QtWidgets import (QApplication, QGraphicsScene, QGraphicsView, QGraphicsPixmapItem, 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
      print(self.m_index)
      self.baseline = 0
      print(len(self.m_icons))
      for i in range(len(self.m_icons)):
          print("ii")
          #icon = QGraphicsItem()
          icon = self.m_icons
          self.a = ((i + self.m_index)*2*math.pi/ len(self.m_icons))
          xs = 170 * math.sin(self.a)
          ys = 170 * math.cos(self.a)
          pos = QPointF(xs, ys)
          icon.setPos(pos)
          # baseline = max(baseline, ys)
          # icon.setBaseLine(baseline)

      self.scene.update()


  def setupScene(self):
      self.scene.setSceneRect(-200, -120, 400, 240)
      names = []
      names.append("img.png")
      names.append('img.png')
      names.append('img.png')
      names.append('img.png')
      names.append('img.png')
      names.append('img.png')
      names.append('img.png')


      for i in names:
          pixmap = QPixmap(i)
          icon = QGraphicsPixmapItem()
          self.scene.addPixmap(pixmap)
          icon.setZValue(0)
          self.m_icons.append(icon)
          print(len(self.m_icons))

  def keyPressEvent(self, e):
      delta = 0
      if e.key() == Qt.Key_Left:
          delta = -1
      elif e.key() == Qt.Key_Right:
          delta = 1

      if self.m_animation.state() == QAbstractAnimation.Stopped and delta:
          self.m_animation.setEndValue(self.m_index + delta)
          print("wwww")
          self.m_animation.start()
          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_())
I am getting error: 
QPropertyAnimation: you're trying to animate a non-existing property index of your QObject

QPropertyAnimation::updateState (index, BlurPicker, ): starting an animation without start value
Reply
#2
You've got a bunch of print statements, which of those(if any) are being called?  Actually, just share all the output, instead of just the error.

It looks like QPropertyAnimation is expecting an object, and a property on that object that it'll animate.  You gave it "index", and you've got an index... method.  So you'd either need to set an index property (ie: self.index = 0.0), or use the @property decorator, followed by @index.setter for your setIndex().  Which means qt is telling you exactly what your problem is... you told it to use a property that doesn't exist.  
Error:
QPropertyAnimation: you're trying to animate a non-existing property index of your QObject
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,785 Apr-06-2019, 11:15 PM
Last Post: ZenWoR

Forum Jump:

User Panel Messages

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