title: How to get selected items from QComboBox to be displayed in QTableWidget in PyQt5? (QComboBox has checkbox to pick items)
body: <p>I have QTableWidget in which I have QComboBox in each row for particular column. My each QCombobox has multiple values with checkboxes. I want to display selected item/s from each combobox in the next respective column 'SelectedMonths' in the same row and remove them when unchecked (Vice-versa).</p>
  
  <p>Until now I have Script ready which gives me what all items have been checked/unchecked but I dont know how to get the index of the row for which combobox is activated. </p>
  
  <p>Snippet to get the workflow</p>
  
  <p><img src="https://i.stack.imgur.com/2XfkK.png" alt=""></p>
  
  <p><strong>Sample Code:</strong></p>
  
  <p><strong>Code Generated by QtDesigner: Demo.py</strong></p>
  
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  
  class Ui_MainWindow(object):
      def setupUi(self, MainWindow):
          MainWindow.setObjectName("MainWindow")
          MainWindow.resize(464, 291)
          self.centralwidget = QtWidgets.QWidget(MainWindow)
          self.centralwidget.setObjectName("centralwidget")
          self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
          self.tableWidget.setGeometry(QtCore.QRect(30, 30, 411, 221))
          self.tableWidget.setRowCount(1)
          self.tableWidget.setColumnCount(2)
          self.tableWidget.setObjectName("tableWidget")
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(0, 0, item)
          item = QtWidgets.QTableWidgetItem()
          self.tableWidget.setItem(0, 1, item)
          self.tableWidget.horizontalHeader().setVisible(False)
          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"))
          __sortingEnabled = self.tableWidget.isSortingEnabled()
          self.tableWidget.setSortingEnabled(False)
          item = self.tableWidget.item(0, 0)
          item.setText(_translate("MainWindow", "Select Months"))
          item = self.tableWidget.item(0, 1)
          item.setText(_translate("MainWindow", "Selected Months"))
          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><strong>Code which I have written: DemoCode.py</strong></p>
  
  <pre><code>from PyQt5 import QtWidgets, QtGui
  from PyQt5.QtWidgets import QTableWidgetItem
  from PyQt5.QtGui import QStandardItem, QStandardItemModel
  from PyQt5.QtCore import Qt
  from datetime import date
  from dateutil.relativedelta import relativedelta
  
  from Demo import Ui_MainWindow
  
  def CheckableCombobox(combo, options):
      model = QStandardItemModel(len(options), 1)
      firstItem = QtGui.QStandardItem("SelectMonths")
      firstItem.setBackground(QtGui.QBrush(QtGui.QColor(200, 200, 200)))
      firstItem.setSelectable(False)
      model.setItem(0, 0, firstItem)
      for i, area in enumerate(options):
          item = QStandardItem(area)
          item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
          item.setData(Qt.Unchecked, Qt.CheckStateRole)
          model.setItem(i+1, 0, item)
      combo.setModel(model)
  
  class DemoCode(QtWidgets.QMainWindow, Ui_MainWindow):                    
      def __init__(self):
          super(DemoCode, self).__init__()
          self.setupUi(self)  
  
          self.rowPosition = self.tableWidget.rowCount()
          for row in range(0,3):
              self.tableWidget.insertRow(self.rowPosition)
              for column in range(0,2):
                  if column == 0:
                      self.ComboBox = QtWidgets.QComboBox()
                      dtStart = date.today()
                      self.Monthlist = []
                      for n in range(1, 5):
                          self.Monthlist.append((dtStart + relativedelta(months=-n)).strftime('1-%b-%Y'))
                      CheckableCombobox(self.ComboBox, self.Monthlist)
                      self.ComboBox.model().itemChanged.connect(self.on_itemChanged)
                      self.tableWidget.setCellWidget(self.rowPosition, column, self.ComboBox)
                  elif column == 1:
                      item = QTableWidgetItem('')
                      self.tableWidget.setItem(self.rowPosition, column, item)
  
              self.rowPosition += 1
  
          self.tableWidget.setColumnWidth(1,150)
  
      def on_itemChanged(self, item):
          current_state = item.data(Qt.CheckStateRole)
          print(current_state, item.text())
  
  if __name__ == "__main__":
      import sys
      app = QtWidgets.QApplication(sys.argv)
      window = DemoCode()    
      window.show()
      sys.exit(app.exec_())
  </code></pre>