1
tableView
의면에 어떻게 색을 추가합니까?Qt tableView - 색상 추가
tableView
의면에 어떻게 색을 추가합니까?Qt tableView - 색상 추가
:
#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));
}
};
다음은 QTableView의 수직 헤더로 HeaderView의 인스턴스를 설정합니다
HeaderView vView;
tableview.setVerticalHeader(&vView);
감사합니다. 이제 효과가있었습니다. 'tableview.setVerticalHeader (& hView);에 대해'tableview.setHorizontalHeader (& hView);를 대체해야합니다. – user628298
사용'QStyledItemDelegate ' –
@ 드미트리 Sazonov 어떻게 tableView의 속성을 잡을까요? Qt :: DisplayRole? 코드로 설명해 주시고, 제가 이해하는 것이 더 낫습니다. – user628298