You could use a delegate
class GridDelegate : public QStyledItemDelegate
{
public:
explicit GridDelegate
(QObject * parent
= 0) : QStyledItemDelegate
(parent
) { }
{
painter->save();
painter
->setPen
(QColor(Qt
::black));
painter->drawRect(option.rect);
painter->restore();
QStyledItemDelegate::paint(painter, option, index);
}
};
int main(int argc, char ** argv)
{
model.setRowCount(5);
model.setColumnCount(5);
for(int r = 0; r < model.rowCount(); r++)
for(int c = 0; c < model.columnCount(); c++)
treeView.setModel(&model);
treeView.setItemDelegate(new GridDelegate(&treeView));
treeView.show();
return app.exec();
}
class GridDelegate : public QStyledItemDelegate
{
public:
explicit GridDelegate(QObject * parent = 0) : QStyledItemDelegate(parent) { }
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
painter->save();
painter->setPen(QColor(Qt::black));
painter->drawRect(option.rect);
painter->restore();
QStyledItemDelegate::paint(painter, option, index);
}
};
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
QStandardItemModel model;
model.setRowCount(5);
model.setColumnCount(5);
for(int r = 0; r < model.rowCount(); r++)
for(int c = 0; c < model.columnCount(); c++)
model.setItem(r, c, new QStandardItem("Item"));
QTreeView treeView;
treeView.setModel(&model);
treeView.setItemDelegate(new GridDelegate(&treeView));
treeView.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks