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. QTableWidget - Uneditable cell.

QTableWidget - Uneditable cell.

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 4 Posters 3.3k Views 1 Watching
  • 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.
  • I Offline
    I Offline
    Igor86
    wrote on last edited by
    #1

    Hello!

    I would need to make the first column of my Table not editable. I have tried the following code and some variations of it, but cant figure out how to do it:

    self.programCorrelationTable.setItem(tableRow, 0, QtWidgets.QTableWidgetItem(str(row[0])).setFlags(QtCore.Qt.ItemFlag.ItemIsEditable))
    

    Any help is very appreciated..

    thank you!

    jsulmJ JonBJ 2 Replies Last reply
    0
    • I Igor86

      Hello!

      I would need to make the first column of my Table not editable. I have tried the following code and some variations of it, but cant figure out how to do it:

      self.programCorrelationTable.setItem(tableRow, 0, QtWidgets.QTableWidgetItem(str(row[0])).setFlags(QtCore.Qt.ItemFlag.ItemIsEditable))
      

      Any help is very appreciated..

      thank you!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @Igor86 said in QTableWidget - Uneditable cell.:

      self.programCorrelationTable.setItem(tableRow, 0, QtWidgets.QTableWidgetItem(str(row[0])).setFlags(QtCore.Qt.ItemFlag.ItemIsEditable))

      This is wrong for several reasons.
      Should be:

      item = QtWidgets.QTableWidgetItem(str(row[0]))
      item.setFlags(item.flags() & ~QtCore.Qt.ItemFlag.ItemIsEditable)
      self.programCorrelationTable.setItem(tableRow, 0, item)
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • I Igor86

        Hello!

        I would need to make the first column of my Table not editable. I have tried the following code and some variations of it, but cant figure out how to do it:

        self.programCorrelationTable.setItem(tableRow, 0, QtWidgets.QTableWidgetItem(str(row[0])).setFlags(QtCore.Qt.ItemFlag.ItemIsEditable))
        

        Any help is very appreciated..

        thank you!

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

        @Igor86 said in QTableWidget - Uneditable cell.:

        QtWidgets.QTableWidgetItem(str(row[0])).setFlags(QtCore.Qt.ItemFlag.ItemIsEditable)

        We are in C++, not JavaScript/jQuery! We do not "chain" calls like this. This is an expression with return result as per void QTableWidgetItem::setFlags(Qt::ItemFlags flags). Which is void so what you have should not compile?

        Not to mention, you are trying to set it to editable, when you say you want it not editable!

        Try e.g.

        EDIT Oh dear, @jsulm has beaten me to reply! He does not take time to explain like I do ;-) Follow his code, read my explanation! :)

        SGaistS 1 Reply Last reply
        1
        • JonBJ JonB

          @Igor86 said in QTableWidget - Uneditable cell.:

          QtWidgets.QTableWidgetItem(str(row[0])).setFlags(QtCore.Qt.ItemFlag.ItemIsEditable)

          We are in C++, not JavaScript/jQuery! We do not "chain" calls like this. This is an expression with return result as per void QTableWidgetItem::setFlags(Qt::ItemFlags flags). Which is void so what you have should not compile?

          Not to mention, you are trying to set it to editable, when you say you want it not editable!

          Try e.g.

          EDIT Oh dear, @jsulm has beaten me to reply! He does not take time to explain like I do ;-) Follow his code, read my explanation! :)

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @JonB There's no compiler involved when executing Python code ;-)

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

          JonBJ 1 Reply Last reply
          1
          • SGaistS SGaist

            @JonB There's no compiler involved when executing Python code ;-)

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

            @SGaist
            OMG, I didn't even notice it was Python! :)

            Which makes it even worse, and confirms my dislike for Python. In that case I wonder what Python/PyQt/PySide does with the return result of setFlags(), which is "void"/"nothing"? Probably something like treats it as None and passes to setItem()... None/ nullptr?

            1 Reply Last reply
            0
            • I Offline
              I Offline
              Igor86
              wrote on last edited by
              #6

              Thank you everybody

              The posted code works. Its only 2 weeks I program in python and am at the very bginning of my learning curve but I am learning a lot thanks to you guys...

              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