def data(self, index, role):
if role == Qt.DecorationRole:
if index.column() == 0:
return QApplication.style().standardIcon(QStyle.SP_DialogYesButton if self.item(index.row()).valid else QStyle.SP_DialogNoButton)
elif role == Qt.TextAlignmentRole:
if index.column() == 0:
return QVariant(Qt.AlignCenter | Qt.AlignVCenter)
图标显示良好但不居中。
答案 0 :(得分:0)
我找到了QStyledItemDelegate的解决方案。
def paint(self, painter, option, index):
QStyledItemDelegate.paint(self, painter, option, index)
QApplication.style().standardIcon(QStyle.SP_DialogYesButton if index.data().valid else QStyle.SP_DialogNoButton).paint(painter, option.rect)