#include <QApplication> #include <QTableWidget>
#include <QPainter>
#include <QStyledItemDelegate>
#include <QHeaderView>
class QLineDelegate : public QStyledItemDelegate
{
public:
QLineDelegate(QTableView* tableView);
protected:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
private:
QPen pen;
QTableView* view;
};
QLineDelegate::QLineDelegate(QTableView* tableView)
{
int gridHint = tableView->style()->styleHint(QStyle::SH_Table_GridLineColor, new QStyleOptionViewItemV4());
QColor gridColor = static_cast<QRgb>(gridHint);
pen = QPen(gridColor, 0, tableView->gridStyle());
view = tableView;
}
void QLineDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,const QModelIndex& index)const
{
QStyledItemDelegate::paint(painter, option, index);
QPen oldPen = painter->pen();
painter->setPen(pen);
//painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
painter->setPen(oldPen);
}
class QLineTableWidget:public QTableWidget
{
public:
QLineTableWidget();
};
QLineTableWidget::QLineTableWidget()
{
setStyleSheet("QTableView::Item{selection-background-color:#101020}");
setStyleSheet("QTableView::Item{background-color:#F0F0F0}");
verticalHeader()->setVisible(false);
horizontalHeader()->setVisible(true);
setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::SingleSelection);
setEditTriggers(QTableView::NoEditTriggers);
setColumnCount(3);
setRowCount(4);
setShowGrid(false);
setItemDelegate(new QLineDelegate(this));
setCurrentCell(-1,-1);
}
int main(int argc,char **argv)
{
QApplication a(argc,argv);
QLineTableWidget widget;
widget.show();
return a.exec();
}