0

私は 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
            )
4

1 に答える 1

0

更新されたデータは updateEditorGeometry を使用して修正できますが、背景色は使用できません。

def updateEditorGeometry( self, editor, option, index ):
    # input data by here will update automatically 
    col = index.column ()
    row = index.row ()
    val = int(self.tm.arraydata[row][col])
    editor.setValue (val)

    editor.setGeometry(rect)
于 2014-02-24T04:46:20.197 に答える