[PyQt] pyqt combobox in header
nenduvel
eenpint at hotmail.com
Tue Sep 1 21:53:07 BST 2009
hello,
in the next code i have a qtableview with comboboxes. is it possible to do
the same with the header of the qtableview? I tried to add the same delegate
to the qheaderview of the qtableview, but i don't see anything happening.
any suggestions?
thanks in advance,
nenduvel
#######################################
#!/usr/bin/env python
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class ComboBoxDelegate(QItemDelegate):
def __init__(self, parent = None):
QItemDelegate.__init__(self, parent)
def createEditor(self, parent, option, index):
editor = QComboBox( parent )
editor.insertItem(0, unicode('A'), QVariant(QString('A')))
editor.insertItem(1, unicode('B'), QVariant(QString('B')))
editor.insertItem(2, unicode('C'), QVariant(QString('C')))
return editor
def setEditorData( self, comboBox, index ):
value = index.model().data(index, Qt.DisplayRole).toInt()
comboBox.setCurrentIndex(value[0])
def setModelData(self, editor, model, index):
value = editor.currentIndex()
model.setData( index, editor.itemData( value, Qt.DisplayRole ) )
def updateEditorGeometry( self, editor, option, index ):
editor.setGeometry(option.rect)
if __name__ == "__main__":
app = QApplication(sys.argv)
model = QStandardItemModel(4, 2)
tableView = QTableView()
tableView.setModel(model)
delegate = ComboBoxDelegate()
tableView.setItemDelegate(delegate)
for row in range(4):
print row
for column in range(2):
print column
index = model.index(row, column, QModelIndex())
model.setData(index, QVariant('A'))
tableView.setWindowTitle("ComboBox Delegate")
tableView.show()
sys.exit(app.exec_())
--
View this message in context: http://www.nabble.com/pyqt-combobox-in-header-tp25244317p25244317.html
Sent from the PyQt mailing list archive at Nabble.com.
More information about the PyQt
mailing list