2010-01-09 47 views
1

我有一個QTableWidget 5列,如何設置列2上的所有項目是一個QProgressBar?pyqt自定義項目代表qtablewidget

我想是這樣的:

self.downloads_table = QtGui.QTableWidget(0, 5) 
self.downloads_table.setItemDelegateForColumn(2, DownloadDelegate(self)) 

其中DownloadDelegate是:

class DownloadDelegate(QItemDelegate): 

    def __init__(self, parent=None): 
    super(DownloadDelegate, self).__init__(parent) 

    def createEditor(self, parent, option, index): 
    return QProgressBar(parent) 

但是進度條不顯示在所有。任何想法?

+1

我剛發現QTableWidget.setCellWidget(),就像魅力一樣。 :) – Marconi 2010-01-09 08:50:16

+3

如果你將其寫成答案並接受它(你可以接受你自己的答案,甚至會給你自學者徽章),那麼這將是很好的,所以這個信息是爲下一個尋找它。 – balpha 2010-01-09 08:59:52

+0

我是那個正在尋找它的人...... @Marconi你可以發佈你的答案。 – 2015-06-27 15:49:25

回答

1

如馬可尼所述返回itemEditable

QTableWidget.setCellWidget(row, column, QWidget) 

增加一個QWidget成(行,列)的細胞,並賦予它的QTableWidget的父。

例如東西沿着這些線路:

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) 

會給你一個1x3表「富」在cell 0,0,在cell 0,1一個QComboBoxcell 0,2一個QCheckBox