[quote=引用 5 楼 a294130128 的回复:] [quote=引用 4 楼 a294130128 的回复:] [quote=引用 3 楼 u011012932 的回复:] 使用代理 setCellWidget,代理是一个QLabel,QLabel里放你要设置的图标即可!这个做法比较简单
[quote=引用 4 楼 a294130128 的回复:] [quote=引用 3 楼 u011012932 的回复:] 使用代理 setCellWidget,代理是一个QLabel,QLabel里放你要设置的图标即可!这个做法比较简单
class IconDelegate : public QStyledItemDelegate { Q_OBJECT public: IconDelegate(QObject *parent = 0): QStyledItemDelegate(parent) { } void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex & index ) const { //判断是不是icon所在的index if(index.column()!=0 && index.row()!=0){ QStyledItemDelegate::paint(painter,option,index); return; } QPixmap pixmap = QPixmap("icon.png"); qApp->style()->drawItemPixmap(painter, option.rect, Qt::AlignCenter, QPixmap(pixmap)); } }; 然后 tableWidget->setItemDelegate(new IconDelegate(this)); tableWidget->setItemDelegateForColumn(colum, new IconDelegate(this)); tableWidget->setItemDelegateForRow(row, new IconDelegate(this));
[quote=引用 3 楼 u011012932 的回复:] 使用代理 setCellWidget,代理是一个QLabel,QLabel里放你要设置的图标即可!这个做法比较简单
使用代理 setCellWidget,代理是一个QLabel,QLabel里放你要设置的图标即可!这个做法比较简单
16,202
社区成员
26,591
社区内容
加载中
试试用AI创作助手写篇文章吧