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. How I remove all data from a row in PySide2 without deleting the row
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved Qt for Python
12 Posts 2 Posters 3.1k 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.
  • B Offline
    B Offline
    BlueBreezy
    wrote on 15 Jul 2019, 09:47 last edited by
    #1

    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!

    J 1 Reply Last reply 15 Jul 2019, 10:45
    0
    • B BlueBreezy
      15 Jul 2019, 09:47

      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!

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 15 Jul 2019, 10:45 last edited by
      #2

      @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 15 Jul 2019, 16:14
      0
      • B Offline
        B Offline
        BlueBreezy
        wrote on 15 Jul 2019, 15:54 last edited by
        #3

        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
        0
        • J jsulm
          15 Jul 2019, 10:45

          @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?

          B Offline
          B Offline
          BlueBreezy
          wrote on 15 Jul 2019, 16:14 last edited by
          #4

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

          J 1 Reply Last reply 16 Jul 2019, 04:18
          0
          • B BlueBreezy
            15 Jul 2019, 16:14

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

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 16 Jul 2019, 04:18 last edited by
            #5

            @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 16 Jul 2019, 05:16
            0
            • J jsulm
              16 Jul 2019, 04:18

              @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...

              B Offline
              B Offline
              BlueBreezy
              wrote on 16 Jul 2019, 05:16 last edited by
              #6

              @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?

              J 1 Reply Last reply 16 Jul 2019, 05:19
              0
              • B BlueBreezy
                16 Jul 2019, 05:16

                @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?

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 16 Jul 2019, 05:19 last edited by jsulm
                #7

                @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 16 Jul 2019, 05:49
                0
                • B Offline
                  B Offline
                  BlueBreezy
                  wrote on 16 Jul 2019, 05:35 last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • J jsulm
                    16 Jul 2019, 05:19

                    @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.

                    B Offline
                    B Offline
                    BlueBreezy
                    wrote on 16 Jul 2019, 05:49 last edited by
                    #9

                    @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())
                    
                    J 1 Reply Last reply 16 Jul 2019, 06:01
                    0
                    • B BlueBreezy
                      16 Jul 2019, 05:49

                      @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())
                      
                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 16 Jul 2019, 06:01 last edited by
                      #10

                      @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 16 Jul 2019, 15:48
                      0
                      • J jsulm
                        16 Jul 2019, 06:01

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

                        window.tableWidget.item(row, col).setText("");
                        
                        B Offline
                        B Offline
                        BlueBreezy
                        wrote on 16 Jul 2019, 15:48 last edited by
                        #11

                        @jsulm oh right okay Let me try that

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          BlueBreezy
                          wrote on 16 Jul 2019, 16:50 last edited by
                          #12

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

                          1 Reply Last reply
                          0

                          1/12

                          15 Jul 2019, 09:47

                          • Login

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