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. [PyQt4] QTableWidget Readonly?

[PyQt4] QTableWidget Readonly?

Scheduled Pinned Locked Moved Unsolved Qt for Python
22 Posts 6 Posters 9.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.
  • D Daniel26

    Ok, sorry for that stupid question, but I'm new to pyQt and object orientated programming.
    QTableWidgetItem is only a cell of the QTableWidget? is that correct?

    I create an instance of QTableWidget as self.addip_tw and added the self.addip_tw to a QGridLayout.
    So I have to do the setFlags for every cell in my Table?

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

    @Daniel26 said in [PyQt4] QTableWidget Readonly?:

    QTableWidgetItem is only a cell of the QTableWidget? is that correct?

    Not exactly, it's an object that will be stored in the model coming with QTableWidget and provide all the necessary data to be rendered by a cell of the table.

    A QTableWidget is a QTableView + a model all packed in one.

    You should check the Model/View Programming chapter in Qt's documentation for a good overview of how it is working.

    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
    • D Offline
      D Offline
      Daniel26
      wrote on last edited by
      #14

      Ok,

      so I set every Cell with an empty QWidgetItem so I can set it to readOnly?

      I'm totally confused....

      JonBJ 1 Reply Last reply
      0
      • D Daniel26

        Ok,

        so I set every Cell with an empty QWidgetItem so I can set it to readOnly?

        I'm totally confused....

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

        @Daniel26
        You can indeed do it as @Denni-0 has said. To my mind, it doesn't really make the cells read-only, but it does stop the user doing anything to edit :) And it's only one line!

        For making the items not-editable, you could look at the code in https://stackoverflow.com/questions/7727863/how-to-make-a-cell-in-a-qtablewidget-read-only/ which is the accepted solution. Other answers there also show @Denni-0 's approach.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Daniel26
          wrote on last edited by
          #16

          hello @ all,

          thanks for the help. I've got it, did it with the QTableWidget.
          But how can I check, if a column is empty?
          A simple "if self.addip_tw.item(x,y)" won't work :)

          Regards

          Daniel

          JonBJ 1 Reply Last reply
          0
          • D Daniel26

            hello @ all,

            thanks for the help. I've got it, did it with the QTableWidget.
            But how can I check, if a column is empty?
            A simple "if self.addip_tw.item(x,y)" won't work :)

            Regards

            Daniel

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

            @Daniel26
            What do you mean by "if a column is empty"? Plus, why do you care if you are choosing to go for the simplest QTreeView.setEditTriggers(QAbstractItemView.NoEditTriggers)?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Daniel26
              wrote on last edited by
              #18

              Sorry, I ment if a cell is empty.

              I store the content of the cells into a dictionary, but only if the first cell of the line is not empty.

              JonBJ 1 Reply Last reply
              0
              • D Daniel26

                Sorry, I ment if a cell is empty.

                I store the content of the cells into a dictionary, but only if the first cell of the line is not empty.

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

                @Daniel26
                The I don't understand why you say

                A simple "if self.addip_tw.item(x,y)" won't work :)

                since https://doc.qt.io/qt-5/qtablewidget.html#item does return nullptr for no item.

                D 1 Reply Last reply
                0
                • JonBJ JonB

                  @Daniel26
                  The I don't understand why you say

                  A simple "if self.addip_tw.item(x,y)" won't work :)

                  since https://doc.qt.io/qt-5/qtablewidget.html#item does return nullptr for no item.

                  D Offline
                  D Offline
                  Daniel26
                  wrote on last edited by
                  #20

                  @JonB
                  if self.addip_tw.item[row,0]:
                  TypeError: 'builtin_function_or_method' object has no attribute 'getitem'

                  JonBJ 1 Reply Last reply
                  0
                  • D Daniel26

                    @JonB
                    if self.addip_tw.item[row,0]:
                    TypeError: 'builtin_function_or_method' object has no attribute 'getitem'

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

                    @Daniel26
                    Please look at your code before saying things "don't work". Could this be because item() is a function and not an array?

                    1 Reply Last reply
                    2
                    • D Offline
                      D Offline
                      Daniel26
                      wrote on last edited by
                      #22

                      Maybe.....fu....I'm blind, sorry.

                      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