Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Solved How I remove all data from a row in PySide2 without deleting the row

    Qt for Python
    2
    12
    1878
    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.
    • B
      BlueBreezy last edited by

      so I have a row on a table using the tableWidget but I want to remove data from the row without deleting the entire row, and hence reuse the row to add other data. I have tried using removeRow but that deletes the entire row which isn't what I am after. I have also tried setting the row to no value with setItem() but that still does not work so can you help!

      Thanks!

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @BlueBreezy last edited by

        @BlueBreezy You can iterate through all columns in that row using https://doc.qt.io/qt-5/qtablewidget.html#item and delete/clear content of each item.

        "I have also tried setting the row to no value with setItem() " - can you show how you did this?

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

        B 1 Reply Last reply Reply Quote 0
        • B
          BlueBreezy last edited by

          Ok thanks I will try that, and how I set it to no value is by doing this ```

          window.tableWidget.setItem(0,0 ,QTableWidgetItem())

          as you can see QTablewWidgetItem is blank and there is no value in the parenthesis

          1 Reply Last reply Reply Quote 0
          • B
            BlueBreezy @jsulm last edited by

            @jsulm wait I dont get it plus isn't that c++ docs

            jsulm 1 Reply Last reply Reply Quote 0
            • jsulm
              jsulm Lifetime Qt Champion @BlueBreezy last edited by

              @BlueBreezy said in How I remove all data from a row in PySide2 without deleting the row:

              isn't that c++ docs

              It is, but it is the same interface in Python but with Python syntax...

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

              B 1 Reply Last reply Reply Quote 0
              • B
                BlueBreezy @jsulm last edited by

                @jsulm So can the same be found here https://doc.qt.io/qtforpython/PySide2/QtWidgets/QTableWidget.html

                also its just

                QTableWidget::item(int row, int column) const
                

                so how would I go about deleting a row with just that?

                jsulm 1 Reply Last reply Reply Quote 0
                • jsulm
                  jsulm Lifetime Qt Champion @BlueBreezy last edited by jsulm

                  @BlueBreezy said in How I remove all data from a row in PySide2 without deleting the row:

                  deleting a row with just that?

                  You don't want to delete a row, right? You want to remove the content in all cells in a row if I understood you correctly. Using item(...) you get the item in the given cell and can then reset its content. For example if you have text in an item you can use https://doc.qt.io/qt-5/qtablewidgetitem.html#setText to set empty string in it.

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

                  B 1 Reply Last reply Reply Quote 0
                  • B
                    BlueBreezy last edited by

                    oh okay I get you sorry I got confused im not deleting the row but let me see

                    1 Reply Last reply Reply Quote 0
                    • B
                      BlueBreezy @jsulm last edited by

                      @jsulm but I think I tried setting the row no no value before but whenever my code tries to put data into it it skips the row because it thinks that there is data there, here's an example

                      window.tableWidget.setItem(0,0 ,QTableWidgetItem())
                      
                      jsulm 1 Reply Last reply Reply Quote 0
                      • jsulm
                        jsulm Lifetime Qt Champion @BlueBreezy last edited by

                        @BlueBreezy I did not suggest to call setData. I suggested to call

                        window.tableWidget.item(row, col).setText("");
                        

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

                        B 1 Reply Last reply Reply Quote 0
                        • B
                          BlueBreezy @jsulm last edited by

                          @jsulm oh right okay Let me try that

                          1 Reply Last reply Reply Quote 0
                          • B
                            BlueBreezy last edited by

                            Thanks for the help let me just check my code to see if it my fault

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post