I have a QTableWidget with 5 columns in it, how do I set all items on column 2 to be a QProgressBar?
I tried something like:
self.downloads_table = QtGui.QTableWidget(0, 5)
self.downloads_table.setItemDelegateForColumn(2, DownloadDelegate(self))
Where DownloadDelegate is:
class DownloadDelegate(QItemDelegate):
def __init__(self, parent=None):
super(DownloadDelegate, self).__init__(parent)
def createEditor(self, parent, option, index):
return QProgressBar(parent)
But the progress bar doesn't s开发者_StackOverflowhow up at all. Any idea?
As Marconi said,
QTableWidget.setCellWidget(row, column, QWidget)
adds a QWidget into the cell at (row, column) and gives it the QTableWidget as parent.
e.g. something along these lines:
table = QTableWidget(1, 3)
item1 = QTableWidgetItem("foo")
comboBox = QComboBox()
checkBox = QCheckBox()
table.setItem(0,0,item1)
table.setCellWidget(0,1,comboBox)
table.setCellWidget(0,2,checkBox)
will give you a 1x3
table with "foo" in cell 0,0
, a QComboBox
in cell 0,1
and a QCheckBox
in cell 0,2
.
The model must return itemEditable
in flags()
精彩评论