qtqtableviewqheaderviewqframeqabstractitemview

How to remove horizontal borders from QHeaderView


I Have QTableView object with horizontal headerView, (vertical I have hidden). I set setShowGrid(false) to remove grid from qtableView, but how can I remove separator borders between QTableView and its horizontal header. I tried:

tableView->horizontalHeader()->setFrameShape(QFrame::VLine)

but without success. thank you


Solution

  • OK I reimplemented paintSection method and now I have what I wanted/

    void MyHeaderView::paintSection(QPainter *painter, const QRect &rect,  int logicalIndex) const
    {
      QString data = model() -> headerData(logicalIndex, orientation(), Qt::DisplayRole).toString();
    
      QFontMetrics fm = painter -> fontMetrics();
    
      painter -> fillRect(rect, QBrush(QColor("white")));
      painter -> drawText(rect, Qt::AlignLeft, data);
    
      painter -> drawLine(rect.topRight(), rect.bottomRight());
    }