Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Star Delegate Example error in python 3.7
QtWS25 Last Chance

Star Delegate Example error in python 3.7

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 3 Posters 476 Views
  • 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.
  • alomA Offline
    alomA Offline
    alom
    wrote on last edited by
    #1

    I've set up the star delegate example, with runs fine under python 2.7 but under 3.7 running into:

    Traceback (most recent call last):
      File "Z:\repos\qtPlayGround\QStyledItemDelegate_Start_Example\starEditor.py", line 25, in sizeHint
        return self.starRating.sizeHint()
    AttributeError: 'StarEditor' object has no attribute 'starRating'
    

    I saw that Python 3 only has new-style classes but is there something that needs to change in the StarEditor class? I'm a bit lost as everything looks fine.

    Cheers

    start delegate files:
    https://doc.qt.io/qtforpython/pyside-examples/pyside2examples-widgets-itemviews-stardelegate-example.html#pyside2-qtwidgets-star-delegate-example

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How are you running the code exactly ?

      I see where the issue is but I'd like to know how you trigger it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • alomA Offline
        alomA Offline
        alom
        wrote on last edited by alom
        #3

        @SGaist
        I just have the three files in a pycharm project and running the stardelegate.py file.
        The error pop up once I enter the edit state of the star cell

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then something else must be off.

          In any case, add

          from starrating import StarRating
          

          Before the the StarEditor class declaration and then

          self.starRating = StarRating()
          

          in its constructor.

          A fix to the example has been submitted.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • alomA Offline
            alomA Offline
            alom
            wrote on last edited by
            #5

            @SGaist
            Thanks! working.
            Any idea why python 2.7 wasn't throwing this error?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              No I don't.

              I checked with with Python 3.7.6 and the example runs without my change because of how python works and the sequence of actions that will trigger the use of that attribute. The starRating attribute should have been set prior to being used in any case so there might be something different on your system but I don't know what it is.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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