如何在tableView
?
答案 0 :(得分:1)
你应该继承QHeaderView并实现你自己的类,如:
#include<QtWidgets>
class HeaderView: public QHeaderView
{
public:
HeaderView():QHeaderView(Qt::Vertical)
{}
void paintSection(QPainter * painter, const QRect & rect, int logicalIndex) const
{
QBrush brush;
if(logicalIndex == 0)
brush.setColor(QColor(Qt::red));
else
brush.setColor(QColor(Qt::blue));
painter->fillRect(rect, brush);
QPen pen(Qt::white);
painter->setPen(pen);
painter->drawText(rect,QString("Row %1").arg(logicalIndex));
}
};
接下来将HeaderView的实例设置为QTableView的垂直标题:
HeaderView vView;
tableview.setVerticalHeader(&vView);