title: How to use QComboBox as delegate with QTableView
body: <p>The code below creates a single <code>QTableView</code>. Double-clicking its item will set it with a delegated <code>QComboBox</code>.</p>
  
  <p><strong>Problem</strong>:<br>
  When the <code>ComboBox</code> is clicked its pull-down menu shows up momentary and then it collapses back to its unrolled state.</p>
  
  <p><img src="https://i.stack.imgur.com/vPEym.png" alt="enter image description here"></p>
  
  <p>If the <code>comboBox</code> would be set to be editable using <code>combox.setEditable(True)</code>, 
  the pull-down menu would stay open as desired. But then the <code>combobox</code>'s items become editable. And it is not what needed. Since the <code>combobox</code>'s items should only be selectable.</p>
  
  <p>How to fix the self-collapsing <code>combobox</code>'s behavior?</p>
  
  <p>P.s. I have noticed then when <code>ComboBox</code> is set to be editable and its pull-down menu is unrolled the model's <code>data()</code> is constantly being called... is self-collapsing behavior could probably triggered by model?</p>
  
  <pre><code>import sys
  from PyQt4.QtCore import *
  from PyQt4.QtGui import *
  
  class ComboDelegate(QItemDelegate):
      comboItems=['Combo_Zero', 'Combo_One','Combo_Two']
      def createEditor(self, parent, option, proxyModelIndex):
          combo = QComboBox(parent)
          combo.addItems(self.comboItems)
          # combo.setEditable(True)
          self.connect(combo, SIGNAL("currentIndexChanged(int)"), self, SLOT("currentIndexChanged()"))
          return combo
  
      def setModelData(self, combo, model, index):
          comboIndex=combo.currentIndex()
          text=self.comboItems[comboIndex]        
          model.setData(index, text)
          print '\t\t\t ...setModelData() 1', text
  
      @pyqtSlot()
      def currentIndexChanged(self): 
          self.commitData.emit(self.sender())
  
  class MyModel(QAbstractTableModel):
      def __init__(self, parent=None, *args):
          QAbstractTableModel.__init__(self, parent, *args)
          self.items=['Data_Item01','Data_Item02','Data_Item03']
  
      def rowCount(self, parent=QModelIndex()):
          return len(self.items)
      def columnCount(self, parent=QModelIndex()):
          return 1
  
      def data(self, index, role):        
          if not index.isValid(): return QVariant()
  
          row=index.row()
          item=self.items[row]
  
          if row&gt;len(self.items): return QVariant()
  
          if role == Qt.DisplayRole:
              print ' &lt;&lt; &gt;&gt; MyModel.data() returning ...', item
              return QVariant(item) 
  
      def flags(self, index):
          return Qt.ItemIsEditable | Qt.ItemIsEnabled
  
      def setData(self, index, text):
          self.items[index.row()]=text
  
  if __name__ == '__main__':
      app = QApplication(sys.argv)
  
      model = MyModel()
      tableView = QTableView()
      tableView.setModel(model)
  
      delegate = ComboDelegate()
  
      tableView.setItemDelegate(delegate)
      tableView.resizeRowsToContents()
  
      tableView.show()
      sys.exit(app.exec_())
  </code></pre>