使用代理:
class CommonDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
CommonDelegate();
private:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
void CommonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem itemOption(option);
if(itemOption.state&QStyle::State_HasFocus)
{
itemOption.state=itemOption.state^QStyle::State_HasFocus;
}
QStyledItemDelegate::paint(painter,itemOption,index);
}
TableView设置:
this->setItemDelegate(new CommonDelegate());
前后对比:
评论区