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. Flags: object cannot be interpreted as an integer
Forum Update on Monday, May 27th 2025

Flags: object cannot be interpreted as an integer

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 3 Posters 1.1k 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.
  • S Offline
    S Offline
    sophia73583
    wrote on 13 Oct 2023, 22:58 last edited by
    #1

    Hi,

    I have been trying to set some flags for my widget, but seems to be running into issue on my Mac. I'm not sure if this is a Mac specific issue:

    # code to make item in a ListWidget non selectable
    list_item.setFlags(list_item.flags() & ~Qt.ItemIsSelectable)
    
    # Error:
    TypeError: 'PySide2.QtCore.Qt.ItemFlags' object cannot be interpreted as an integer
    

    I'm getting the same error when setting WindowFlags and WindowTypes. Is this a MacOS specific issue or python specific issue?

    1 Reply Last reply
    0
    • S sophia73583
      16 Oct 2023, 18:48

      @SGaist

      I see! Although most of the references I found online all use setFlags (e.g. https://forum.qt.io/topic/64392/how-can-i-setflags-as-i-setitem/2).

      AttributeError: 'PySide2.QtWidgets.QListWidgetItem' object has no attribute 'setFlag'. Did you mean: 'setFlags'?
      

      If & ~ is not the right way to disable a flag in python, what is the right way?

      S Offline
      S Offline
      sophia73583
      wrote on 16 Oct 2023, 19:42 last edited by
      #4

      Using and instead of & fixed my issue. Might have been issue with a later version of PySide.

      S J 2 Replies Last reply 16 Oct 2023, 20:03
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 14 Oct 2023, 18:24 last edited by
        #2

        Hi,

        It has nothing to do with macOS rather Python.

        While I can't check right now, one thing you can do in between is the use the setFlag method to disable the specific flag you want to remove.

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

        S 1 Reply Last reply 16 Oct 2023, 18:48
        0
        • S SGaist
          14 Oct 2023, 18:24

          Hi,

          It has nothing to do with macOS rather Python.

          While I can't check right now, one thing you can do in between is the use the setFlag method to disable the specific flag you want to remove.

          S Offline
          S Offline
          sophia73583
          wrote on 16 Oct 2023, 18:48 last edited by
          #3

          @SGaist

          I see! Although most of the references I found online all use setFlags (e.g. https://forum.qt.io/topic/64392/how-can-i-setflags-as-i-setitem/2).

          AttributeError: 'PySide2.QtWidgets.QListWidgetItem' object has no attribute 'setFlag'. Did you mean: 'setFlags'?
          

          If & ~ is not the right way to disable a flag in python, what is the right way?

          S 1 Reply Last reply 16 Oct 2023, 19:42
          0
          • S sophia73583
            16 Oct 2023, 18:48

            @SGaist

            I see! Although most of the references I found online all use setFlags (e.g. https://forum.qt.io/topic/64392/how-can-i-setflags-as-i-setitem/2).

            AttributeError: 'PySide2.QtWidgets.QListWidgetItem' object has no attribute 'setFlag'. Did you mean: 'setFlags'?
            

            If & ~ is not the right way to disable a flag in python, what is the right way?

            S Offline
            S Offline
            sophia73583
            wrote on 16 Oct 2023, 19:42 last edited by
            #4

            Using and instead of & fixed my issue. Might have been issue with a later version of PySide.

            S J 2 Replies Last reply 16 Oct 2023, 20:03
            0
            • S sophia73583 has marked this topic as solved on 16 Oct 2023, 19:42
            • S sophia73583
              16 Oct 2023, 19:42

              Using and instead of & fixed my issue. Might have been issue with a later version of PySide.

              S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 16 Oct 2023, 20:03 last edited by SGaist
              #5

              For setFlag, it's a method of the QFlags class.

              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
              • S sophia73583
                16 Oct 2023, 19:42

                Using and instead of & fixed my issue. Might have been issue with a later version of PySide.

                J Offline
                J Offline
                JonB
                wrote on 16 Oct 2023, 21:45 last edited by JonB
                #6

                @sophia73583 said in Flags: object cannot be interpreted as an integer:

                Using and instead of & fixed my issue. Might have been issue with a later version of PySide.

                It might have fixed the error but I am surprised/you seem lucky it gives you the correct behaviour. In Python & is bit-wise AND, which ought be wanted here, while the and you are now using is logical True/False result.

                1 Reply Last reply
                2

                5/6

                16 Oct 2023, 20:03

                • Login

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