Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PyQt5 blurpicker example
Qt 6.11 is out! See what's new in the release blog

PyQt5 blurpicker example

Scheduled Pinned Locked Moved Unsolved Language Bindings
pyqtpyqt5python3pythonqtcreator
5 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alekssandrap
    wrote on last edited by
    #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 (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_())
    
    the_T 1 Reply Last reply
    0
    • A alekssandrap

      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_())
      
      the_T Offline
      the_T Offline
      the_
      wrote on last edited by
      #2

      @alekssandrap said in PyQt5 blurpicker example:
      What do you exactly mean with

      but I cant get the right solution .

      ?

      Any errors, any crashes, other unexpected behaviour?

      -- No support in PM --

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alekssandrap
        wrote on last edited by
        #3

        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

        the_T 1 Reply Last reply
        0
        • A alekssandrap

          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

          the_T Offline
          the_T Offline
          the_
          wrote on last edited by
          #4

          @alekssandrap

          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 use i instead of names in pixmap = ...

          also there seems to be a typo self.m_animation.star() should be self.m_animation.start()

          -- No support in PM --

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alekssandrap
            wrote on last edited by
            #5

            Thank you! I didnt noticed that. I did correct this mistakes, but still getting the same error:( and empty window :/

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved