I am displaying informations from a Database with a QTableView
. I would like the fields to be displayed as a combobox so the user can modify them easily.
I read a lot of things about custom delegate items and flags having to be set to IsUserCheckable
, but I don't understand how all of this is supposed to work.
I tried a couple of things with the flags and role, but with strictly no effect, so there really is something important that I am missing.
I would really appreciate a working code example of this, or at least some nice explanation if someone has that开发者_JAVA百科 at hand :)
Here some example, but if you want something more advanced see QItemDelegate Class Reference.
import sys
from PyQt4 import QtGui, QtCore
class Example(QtGui.QMainWindow):
def __init__(self):
super(Example, self).__init__()
table= QtGui.QTableWidget(5, 5)
self.setCentralWidget(table)
combobox = QtGui.QComboBox()
combobox.addItem('one')
combobox.addItem('two')
table.setCellWidget(3, 4, combobox)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = Example()
window.setWindowTitle('ComboBox in Table Example')
window.resize(600, 400)
window.show()
sys.exit(app.exec_())
精彩评论