私は Python の NEWBIE 開発者です。これは私の最初の Python スクリプトです。QProgressBar を QTableview (QAbstractTableModel) に QItemDelegate として追加したところ、機能しました。QProgressBar は表示されましたが、QTableview を編集またはソートすると自動的に更新されません。QItemDelegate の Background color 、alignment 、 edit は役割に従っていませんか? 何か案が ?setmodeldata または seteditordata を使用する必要がありますか? この場合の例はありますか?
これが QAbstractTableModel のクラスです
def data(self, index, role):
col = index.column ()
row = index.row()
if not index.isValid():
return QVariant()
elif role == Qt.BackgroundColorRole and row%2 == 0 :
return QVariant(QColor(60,60,60))
elif role == Qt.DisplayRole and col != 3 :
return QVariant(self.arraydata[row][col])
elif role == Qt.EditRole and col != 3 :
return QVariant(self.arraydata[row][col])
elif role == Qt.ToolTipRole :
return QVariant("tool tips")
elif role == Qt.TextAlignmentRole:
return QVariant(Qt.AlignCenter | Qt.AlignCenter)
ここにデリゲートコードがあります:
class progressDelegate(QItemDelegate):
def __init__(self, parent ):
QItemDelegate.__init__(self, parent )
self.tb = self.parent().shotslistTable
self.tm = self.parent().tm
def paint(self, painter, option, index):
self.pbar = QProgressBar(self.parent())
col = index.column ()
row = index.row ()
self.pbar.setMinimum(0)
self.pbar.setMaximum(100)
self.pbar.setValue (int(self.tm.arraydata[row][col]))
self.pbar.setMaximumHeight(24)
if not self.tb.indexWidget(index):
self.tb.setIndexWidget(
index,
self.pbar
)