qt tableview里面添加控件

时间:2021-04-04 08:43:26
在QStyledItemDelegate的paint方法里面
 
void MyItemModelDeletage::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    HtItemModelDeletage::paint(painter,option,index);
    if(index.column() == 0)
 
    {
                painter->save();
                QPushButton *button = new QPushButton(this);
                button->resize(option.rect.size() );
                painter->translate(option.rect.topLeft());                
                button->render(painter, QPoint(), QRegion(), QWidget::DrawChildren );
                painter->restore();
    }
}