1

我有一个包含 5 列的 QTableWidget,如何将第 2 列的所有项目设置为 QProgressBar?

我试过类似的东西:

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)

但是进度条根本不显示。任何的想法?

4

2 回答 2

2

正如马可尼所说,

QTableWidget.setCellWidget(row, column, QWidget) 

将 QWidget 添加到 (row, column) 的单元格中,并将 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桌子,里面有 "foo" in cell 0,0, a QComboBoxincell 0,1和 a QCheckBoxin cell 0,2

于 2012-02-19T20:27:13.753 回答
0

模型必须itemEditable返回flags()

于 2010-10-19T16:13:30.500 回答