PySide / PyQt QStyledItemDelegate list in table

Posted by danodonovan on Stack Overflow See other posts from Stack Overflow or by danodonovan
Published on 2011-01-31T23:23:21Z Indexed on 2011/01/31 23:25 UTC
Read the original article Hit count: 442

Filed under:
|
|

Dear All,

I'm trying to create a table of lists in Python with Qt (PySide/PyQt - matters not) and my lists are squashed into the table cells.

Is there a way to get the list delegates to 'pop out' of their cells? I've attached a simple code snippet - replace 'PySide' with 'PyQt4' depending on your preference

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_())

If you hadn't guessed I'm pretty new to this Qt lark

Thanks in advance, Dan

© Stack Overflow or respective owner

Related posts about python

Related posts about pyqt