我开始在 QGIS 3 上创建插件,我的插件需要 QTableView 中的进度条。我想弄清楚如何在 PyQt5 的 QTableView 中添加一列进度条。但是我找不到与我的问题相关的任何代码或资源。
我的桌子

w= self.tasklist_tabv
delegate = ProgressDelegate(w)
w.setItemDelegateForColumn(2, delegate)
w.setHorizontalHeaderLabels(["ID", "Name", "Progress"])
for r, (_id, _name, _progress) in enumerate(data):
it_id = QtGui.QTableWidgetItem(_id)
it_name = QtGui.QTableWidgetItem(_name)
it_progress = QtGui.QTableWidgetItem()
chkBoxItem = QtGui.QTableWidgetItem()
chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
chkBoxItem.setCheckState(QtCore.Qt.Unchecked)
it_progress.setData(QtCore.Qt.DisplayRole+1000, _progress)
w.insertRow(w.rowCount())
for c, item in enumerate((it_id, it_name, it_progress)):
w.setItem(r, c, item)
for c, item in enumerate((it_id, it_name, chkBoxItem)):
w.setItem(r, c+1, item)
class ProgressDelegate(QtGui.QStyledItemDelegate):
def paint(self, painter, option, index):
progress = index.data(QtCore.Qt.DisplayRole+1000)
opt = QtGui.QStyleOptionProgressBar() …Run Code Online (Sandbox Code Playgroud)