title: How to Copy and Paste multiple Cells in QTableWidget in PyQt5?
body: <p>I have a Qtablewidget shown below. I want to copy multiple cells from the table and paste in other  row in the same table. </p>
  
  <p>So far, I can do the same on single cell, but is there a way i can do multiple cells at the same time??</p>
  
  <p>Also, if possible, to copy multiple rows and paste it in same table below?</p>
  
  <p>I tried looking at some answers in SO but quite didn't get it to implement in PyQt5.</p>
  
  <p>Thanks in advance. </p>
  
  <p><a href="https://i.stack.imgur.com/7ahpw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7ahpw.jpg" alt="Snippet for Single Row Copy/Paste"></a></p>
  
  <p><a href="https://i.stack.imgur.com/8R7ZT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8R7ZT.jpg" alt="Snippet for multiple Row Copy/Paste "></a></p>
  
  <p>Sample Code (By QtDesigner):</p>
  
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  
  
  class Ui_MainWindow(object):
      def setupUi(self, MainWindow):
          MainWindow.setObjectName("MainWindow")
          MainWindow.resize(1048, 600)
          self.centralwidget = QtWidgets.QWidget(MainWindow)
          self.centralwidget.setObjectName("centralwidget")
          self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
          self.tableWidget.setGeometry(QtCore.QRect(40, 40, 861, 511))
          self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.AnyKeyPressed|QtWidgets.QAbstractItemView.DoubleClicked|QtWidgets.QAbstractItemView.EditKeyPressed)
          self.tableWidget.setRowCount(5)
          self.tableWidget.setColumnCount(5)
          self.tableWidget.setObjectName("tableWidget")
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setHorizontalHeaderItem(0, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setHorizontalHeaderItem(1, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setHorizontalHeaderItem(2, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setHorizontalHeaderItem(3, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setHorizontalHeaderItem(4, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(0, 0, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(0, 1, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(0, 2, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(0, 3, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(0, 4, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(1, 0, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(1, 1, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(1, 2, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(1, 3, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(1, 4, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(2, 0, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(2, 1, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(2, 2, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(2, 3, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(2, 4, item)
          self.tableWidget.horizontalHeader().setVisible(True)
          self.tableWidget.verticalHeader().setVisible(False)
          MainWindow.setCentralWidget(self.centralwidget)
          self.statusbar = QtWidgets.QStatusBar(MainWindow)
          self.statusbar.setObjectName("statusbar")
          MainWindow.setStatusBar(self.statusbar)
  
          self.retranslateUi(MainWindow)
          QtCore.QMetaObject.connectSlotsByName(MainWindow)
  
      def retranslateUi(self, MainWindow):
          _translate = QtCore.QCoreApplication.translate
          MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
          item = self.tableWidget.horizontalHeaderItem(0)
          item.setText(_translate("MainWindow", "Name"))
          item = self.tableWidget.horizontalHeaderItem(1)
          item.setText(_translate("MainWindow", "ID"))
          item = self.tableWidget.horizontalHeaderItem(2)
          item.setText(_translate("MainWindow", "City"))
          item = self.tableWidget.horizontalHeaderItem(3)
          item.setText(_translate("MainWindow", "Number"))
          item = self.tableWidget.horizontalHeaderItem(4)
          item.setText(_translate("MainWindow", "Occupation"))
          __sortingEnabled = self.tableWidget.isSortingEnabled()
          self.tableWidget.setSortingEnabled(False)
          item = self.tableWidget.item(0, 0)
          item.setText(_translate("MainWindow", "Mark"))
          item = self.tableWidget.item(0, 1)
          item.setText(_translate("MainWindow", "1"))
          item = self.tableWidget.item(0, 2)
          item.setText(_translate("MainWindow", "Newyork"))
          item = self.tableWidget.item(0, 3)
          item.setText(_translate("MainWindow", "4796423643344"))
          item = self.tableWidget.item(0, 4)
          item.setText(_translate("MainWindow", "Teacher"))
          item = self.tableWidget.item(1, 0)
          item.setText(_translate("MainWindow", "Taylor"))
          item = self.tableWidget.item(1, 1)
          item.setText(_translate("MainWindow", "2"))
          item = self.tableWidget.item(1, 2)
          item.setText(_translate("MainWindow", "Chicago"))
          item = self.tableWidget.item(1, 3)
          item.setText(_translate("MainWindow", "43683284"))
          item = self.tableWidget.item(1, 4)
          item.setText(_translate("MainWindow", "Nurse"))
          self.tableWidget.setSortingEnabled(__sortingEnabled)
  
  
  if __name__ == "__main__":
      import sys
      app = QtWidgets.QApplication(sys.argv)
      MainWindow = QtWidgets.QMainWindow()
      ui = Ui_MainWindow()
      ui.setupUi(MainWindow)
      MainWindow.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>Derived Class:</p>
  
  <pre><code>from PyQt5 import QtWidgets
  
  from demo import Ui_MainWindow
  
  class demo_code(QtWidgets.QMainWindow, Ui_MainWindow):                    
      def __init__(self):
          super(demo_code, self).__init__()
          self.setupUi(self) 
  
  
  
  if __name__ == "__main__":
      import sys
      app = QtWidgets.QApplication(sys.argv)
      window = demo_code()    
      window.show()
      sys.exit(app.exec_())
  </code></pre>