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


Messages In This Thread
PyQt5 blurpicker example - by alekssandrap - Feb-16-2017, 12:48 PM
RE: PyQt5 blurpicker example - by nilamo - Feb-20-2017, 10:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,847 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