Pergunta

I'm trying to make a border for rows in QTableWidget with different ways, but all solutions don't respond my requirements. All that I want, is to draw a rectangle around a whole row. I had try QStyledItemDelegate class, but that is not my way, because delegates are used only for item[ row, column ], not for the whole rows or columns.

Here is wrong solution:

/// @brief Рисуем границу вокруг строки. 
class DrawBorderDelegate : public QStyledItemDelegate
{
public:
     DrawBorderDelegate( QObject* parent = 0 ) : QStyledItemDelegate( parent ) {}
     void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;

}; // DrawBorderDelegate

void DrawBorderDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
     QStyleOptionViewItem opt = option;

     painter->drawRect( opt.rect );

     QStyledItemDelegate::paint( painter, opt, index );  
}

And somewhere in code:

tableWidget->setItemDelegateForRow( row, new DrawBorderDelegate( this ) );

Thanks for help!

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top