Pregunta

Estoy tratando de crear una tabla de listas en Python con Qt (Pyside/Pyqt - importa no) y mis listas se aplican en las celdas de la tabla.

¿Hay alguna manera de hacer que los delegados de la lista 'salgan' de sus celdas? He adjuntado un fragmento de código simple - reemplazar PySide con PyQt4 Dependiendo de su preferencia

from PySide import QtCore, QtGui

class ListDelegate(QtGui.QStyledItemDelegate):

  def createEditor(self, parent, option, index):
    editor = QtGui.QListWidget(parent)
    for i in range( 12 ):
      editor.addItem('list item %d' % i)

    return editor

if __name__ == '__main__':

  import sys

  app = QtGui.QApplication(sys.argv)

  model = QtGui.QStandardItemModel(2, 2)
  tableView = QtGui.QTableView()

  delegate = ListDelegate()
  tableView.setItemDelegate(delegate)

  tableView.setModel(model)

  for row in range(2):
    for column in range(2):

      item = QtGui.QStandardItem( 'None' )

      model.setItem(row, column, item)

  tableView.setWindowTitle('example')
  tableView.show()
  sys.exit(app.exec_())
¿Fue útil?

Solución

Entonces la respuesta es usar

QComboBox

más bien que

QListWidget

Entonces la línea 6 se convierte en

editor = QtGui.QComboBox(parent)

Y todo esta bien con el mundo. Espero que esto ayude a alguien...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top