Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Bool of .checkState() is always True?
QtWS25 Last Chance

Bool of .checkState() is always True?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 988 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
    somethingvague
    wrote on last edited by
    #1

    I have a QTableWidget with checkable items. In the last version of PySide I used (6.1.2) before what I updated to recently (6.4.0), taking bool() of .checkState() would return True/False depending on if the box is checked. Now it always returns True. I have tested this with

    print(item.checkState())
    print(bool(item.checkState())
    

    And regardless of whether or not the first statement prints CheckState.Checked or CheckState.Unchecked, the second statement always prints True. Ideas?

    JonBJ 1 Reply Last reply
    0
    • S somethingvague

      I have a QTableWidget with checkable items. In the last version of PySide I used (6.1.2) before what I updated to recently (6.4.0), taking bool() of .checkState() would return True/False depending on if the box is checked. Now it always returns True. I have tested this with

      print(item.checkState())
      print(bool(item.checkState())
      

      And regardless of whether or not the first statement prints CheckState.Checked or CheckState.Unchecked, the second statement always prints True. Ideas?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @somethingvague
      What about

      print(item.checkState() == Qt.Checked)
      # or
      print(item.checkState() != Qt.Unchecked)
      

      [It's possible the Checked/Unchecked got moved out from Qt namespace to a different one at Qt6.x, I don't know. Ah, yes, at PyQt6 you might find your need to use Qt.CheckState.Checked/Unchecked?]

      The reason is probably something to do with https://stackoverflow.com/questions/72161415/qt-checkstate-checked-2-and-qt-checkstate-checked-0

      1 Reply Last reply
      1
      • S Offline
        S Offline
        somethingvague
        wrote on last edited by
        #3

        @JonB said in Bool of .checkState() is always True?:

        print(item.checkState() == Qt.Checked)
        or
        print(item.checkState() != Qt.Unchecked)

        These work for my purposes, but I am curious as to why the checkStates() can no longer be used as booleans. It was pretty convenient.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Take a look at

          print(int(item.checkState())
          

          I would guess ist not 0 - but according to the docs it should.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          S 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            Take a look at

            print(int(item.checkState())
            

            I would guess ist not 0 - but according to the docs it should.

            S Offline
            S Offline
            somethingvague
            wrote on last edited by
            #5

            @Christian-Ehrlicher

            That results in the following error:

            int() argument must be a string, a bytes-like object or a number, not 'CheckState'
            
            JonBJ 1 Reply Last reply
            0
            • S somethingvague

              @Christian-Ehrlicher

              That results in the following error:

              int() argument must be a string, a bytes-like object or a number, not 'CheckState'
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @somethingvague
              ...which somewhere along the line is the issue...
              Now you would have to find out exactly how bool() behaves in such a situation.
              One thought: you didn't change your Python version between PySide 6.1.2 and 6.4.0 did you?
              It's not clear to me whether this is an expected change or an inadvertent happenstance.
              PySide6 (PyQt6?) may have been making more of an effort to separate off treating enumerated types from integers.

              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