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. How can I setFlags as I setItem?
QtWS25 Last Chance

How can I setFlags as I setItem?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 4.5k 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.
  • L Offline
    L Offline
    Lobstw
    wrote on last edited by Lobstw
    #1

    Is there any way of setting item flags as I set the item for a table?

    Trying the code below will result in the item not being set at all:

    my_table.setItem(0,0,QtWidgets.QTableWidgetItem("John").setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled))
    

    Qt doesn't like this either:

    item = QtWidgets.QTableWidgetItem("John").setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
    my_table.setItem(0,0,item)
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I'm not a Python expert but I believe it should be something like this:

      item = QtWidgets.QTableWidgetItem("John")
      item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
      my_table.setItem(0,0,item)
      
      L 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        I'm not a Python expert but I believe it should be something like this:

        item = QtWidgets.QTableWidgetItem("John")
        item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
        my_table.setItem(0,0,item)
        
        L Offline
        L Offline
        Lobstw
        wrote on last edited by
        #3

        @Chris-Kawa Yes, I know this way works. I was just wondering if it can be set at the same time to save lines declaring a variable and setting flags indivudally to the variable..

        In any case: I've found an answer that seems a lot more practical in my case (http://stackoverflow.com/questions/24024815/set-a-whole-column-in-qtablewidget-read-only-in-python/24026472#2402647) It uses setItemDelegateForColumn to make an entire column "read only"

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4
          item = QtWidgets.QTableWidgetItem("John").setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
          

          Again, not a Python expert, but this looks just wrong. It assigns a result of a setFlags function to item. But setFlags does not return any value so there is nothing to assign. In c++ at least this wouldn't even compile.

          1 Reply Last reply
          1
          • S sophia73583 referenced this topic on

          • Login

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