Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved How can I setFlags as I setItem?

    General and Desktop
    2
    4
    2991
    Loading More Posts
    • 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
      Lobstw last edited by Lobstw

      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 Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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 Reply Quote 0
        • L
          Lobstw @Chris Kawa last edited by

          @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 Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by

            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 Reply Quote 1
            • First post
              Last post