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 content of data from a row in PySide2 without deleting the row

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

Scheduled Pinned Locked Moved Unsolved Qt for Python
10 Posts 4 Posters 698 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.
  • Y Offline
    Y Offline
    yashi95
    wrote on last edited by
    #1

    How I remove all data from a row in PySide2 without deleting the row, I try with setRowCount but not succeed I want to delete the content of data in a selected row in one table which will reflect another table as well

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Which widget are you using ?
      Which model are you using ?

      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
      • Y Offline
        Y Offline
        yashi95
        wrote on last edited by
        #3

        I am Using QTableWidget in pySide2

        1 Reply Last reply
        0
        • eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by eyllanesc
          #4

          @yashi95 use:

          for column in range(your_tablewidget.columnCount()):
              item = QTableWidgetItem()
              your_tablewidget.setItem(row, column, item)
          

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          SGaistS 1 Reply Last reply
          0
          • eyllanescE eyllanesc

            @yashi95 use:

            for column in range(your_tablewidget.columnCount()):
                item = QTableWidgetItem()
                your_tablewidget.setItem(row, column, item)
            
            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @eyllanesc Rather than recreating items all the time just empty the content of the ones already existing.

            for column in range(your_tablewidget.columnCount()):
                your_tablewidget.item(row, column).setText("")
            

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

            Y 1 Reply Last reply
            0
            • SGaistS SGaist

              @eyllanesc Rather than recreating items all the time just empty the content of the ones already existing.

              for column in range(your_tablewidget.columnCount()):
                  your_tablewidget.item(row, column).setText("")
              
              Y Offline
              Y Offline
              yashi95
              wrote on last edited by yashi95
              #6

              @SGaist thank you, but can you tell me if I have one table in that I have some data and one delete button and also I have one more table with the same content but I select the only first table of the row which have delete button when I click on delete button data should delete both tables

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                If you are showing the exact same content on several widget then you should rather go with a QTableView and share a QStandardItemModel between the two. If you want to stay with QTableWidget then you have to do the synchronisation yourself.

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

                Y 2 Replies Last reply
                0
                • SGaistS SGaist

                  If you are showing the exact same content on several widget then you should rather go with a QTableView and share a QStandardItemModel between the two. If you want to stay with QTableWidget then you have to do the synchronisation yourself.

                  Y Offline
                  Y Offline
                  yashi95
                  wrote on last edited by
                  #8

                  @SGaist okay understood thank you

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    If you are showing the exact same content on several widget then you should rather go with a QTableView and share a QStandardItemModel between the two. If you want to stay with QTableWidget then you have to do the synchronisation yourself.

                    Y Offline
                    Y Offline
                    yashi95
                    wrote on last edited by
                    #9

                    @SGaist Can you tell me how we can find row through the content or data/item in the QtableWidget?

                    JonBJ 1 Reply Last reply
                    0
                    • Y yashi95

                      @SGaist Can you tell me how we can find row through the content or data/item in the QtableWidget?

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

                      @yashi95
                      Look at:
                      https://doc.qt.io/qt-5/qtablewidget.html#item
                      https://doc.qt.io/qt-5/qtablewidget.html#itemFromIndex
                      https://doc.qt.io/qt-5/qtablewidget.html#findItems
                      https://doc.qt.io/qt-5/qtablewidget.html#indexFromItem

                      Depending on what you have/what you want map to, any of these may be relevant.

                      1 Reply Last reply
                      1

                      • Login

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