How do I assign a border to a specific QTableWidgetItem or a row in a QTableWidget?

一笑奈何 提交于 2019-11-29 08:39:06

To change the border itself you'll probably need to create a custom delegate that does something along these lines:

class MyDelegate : public QItemDelegate {
  public:
    MyDelegate( QObject *parent ) : QItemDelegate( parent ) { }
    void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const {
      QItemDelegate::paint( painter, option, index );
      if( /* some condition */ ) {
         painter->setPen( Qt::red );
         painter->drawRect( option.rect );
      }
    }
}

Then you can call:

myTableWidget->setItemDelegate( new MyDelegate(this) );

You can use QTableWidgetItem::setData() and the QModelIndex::data() functions to pass the necessary information back and forth between your table and the delegate

See the qt documentation for QItemDelegate

AFAIK, you can highlight the cell with a different color. I don't see any option that changes only the border of the cell.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!