title: QTableWidget Drag/Drop rows does not change their location when accessing by index
body: <p>I have a QTableWidget, that allows moving of rows by dragging and dropping.</p>
  <p>The initial table looks as follows:</p>
  <p><a href="https://i.stack.imgur.com/jCHSJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jCHSJ.png" alt="enter image description here" /></a></p>
  <p>If clicking on the button,  it prints all the values as they are in the table.</p>
  <p>Now after dragging row 2 to the the position of row 4, the output does not change.</p>
  <p><a href="https://i.stack.imgur.com/WgA6E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WgA6E.png" alt="enter image description here" /></a></p>
  <p>Output:</p>
  <pre><code>Item in row 0, col 0 has value Name
  Item in row 0, col 1 has value City
  Item in row 1, col 0 has value Aloysius
  Item in row 1, col 1 has value Indore
  Item in row 2, col 0 has value Alan
  Item in row 2, col 1 has value Bhopal
  Item in row 3, col 0 has value Arnavi
  Item in row 3, col 1 has value Mandsaur
  </code></pre>
  <p>The expected output:</p>
  <pre><code>Item in row 0, col 0 has value Name
  Item in row 0, col 1 has value City
  Item in row 1, col 0 has value Alan
  Item in row 1, col 1 has value Bhopal
  Item in row 2, col 0 has value Arnavi
  Item in row 2, col 1 has value Mandsaur
  Item in row 3, col 0 has value Aloysius
  Item in row 3, col 1 has value Indore
  </code></pre>
  <p>Why is this the case and how can I print all the rows by their actual, new location?</p>
  <p>Example:</p>
  <pre><code>import sys
  import PyQt5
  
  from PyQt5.QtCore import *#QPointF, QRectF
  from PyQt5.QtGui import *#QPainterPath, QPolygonF, QBrush,QPen,QFont,QColor, QTransform
  from PyQt5.QtWidgets import *#QApplication, QGraphicsScene, QGraphicsView, QGraphicsSimpleTextIt
  
  
  class App(QWidget):
      def __init__(self):
          super().__init__()
          self.title = 'PyQt5 - QTableWidget'
          self.left = 0
          self.top = 0
          self.width = 300
          self.height = 200
  
          self.setWindowTitle(self.title)
          self.setGeometry(self.left, self.top, self.width, self.height)
  
          self.tableWidget = QTableWidget()
          self.tableWidget.verticalHeader().setSectionsMovable(True)
          self.tableWidget.verticalHeader().setDragEnabled(True)
          self.tableWidget.verticalHeader().setDragDropMode(QAbstractItemView.InternalMove)
  
          # Row count
          self.tableWidget.setRowCount(4)
  
          # Column count
          self.tableWidget.setColumnCount(2)
  
          self.tableWidget.setItem(0, 0, QTableWidgetItem(&quot;Name&quot;))
          self.tableWidget.setItem(0, 1, QTableWidgetItem(&quot;City&quot;))
          self.tableWidget.setItem(1, 0, QTableWidgetItem(&quot;Aloysius&quot;))
          self.tableWidget.setItem(1, 1, QTableWidgetItem(&quot;Indore&quot;))
          self.tableWidget.setItem(2, 0, QTableWidgetItem(&quot;Alan&quot;))
          self.tableWidget.setItem(2, 1, QTableWidgetItem(&quot;Bhopal&quot;))
          self.tableWidget.setItem(3, 0, QTableWidgetItem(&quot;Arnavi&quot;))
          self.tableWidget.setItem(3, 1, QTableWidgetItem(&quot;Mandsaur&quot;))
  
          # Table will fit the screen horizontally
          self.tableWidget.horizontalHeader().setStretchLastSection(True)
          self.tableWidget.horizontalHeader().setSectionResizeMode(
              QHeaderView.Stretch)
  
          self.layout = QVBoxLayout()
          self.layout.addWidget(self.tableWidget)
  
          self.button = QPushButton(&quot;Print all the values in the table, in the right order!&quot;)
  
          def get_all_the_values_in_the_table():
              #row_counter = 0
              print(&quot;  &quot;)
              print(&quot;  &quot;)
              for row in range(self.tableWidget.rowCount()):
  
                  for col in range(self.tableWidget.columnCount()):
                      print(&quot;Item in row &quot;+str(row)+&quot;, col &quot;+str(col)+&quot; has value &quot;+str(self.tableWidget.item(row,col).text()))
  
          self.button.clicked.connect(lambda: get_all_the_values_in_the_table())
          self.layout.addWidget(self.button)
  
          self.setLayout(self.layout)
  
          # Show window
          self.show()
  
  
  
  
  
  
  if __name__ == '__main__':
      app = QApplication(sys.argv)
      ex = App()
      sys.exit(app.exec_())
  </code></pre>
  <hr />
  <p>Edit 1:</p>
  <p>Thought that perhaps the item has the same location in the table, but a different index. Yet trying to solve this by getting the index does not work neither. Where's the trick?</p>
  <pre><code>print(&quot;Item in row &quot;+str(row_)+&quot;, col &quot;+str(col_)+&quot; has value &quot;+str(self.tableWidget.itemFromIndex(self.tableWidget.indexFromItem(self.tableWidget.item(row_,col_))).text()))
  </code></pre>