Alright, here's an example:
#include <QtGui>
{
public:
{
setColumnCount(5);
}
protected:
{
for (int i = 0; i < header()->count(); ++i)
{
// draw only visible sections starting from second column
if (header()->isSectionHidden(i) || header()->visualIndex(i) <= 0)
continue;
// position mapped to viewport
int pos = header()->sectionViewportPosition(i) - 1;
if (pos > 0)
}
}
void scrollContentsBy(int dx, int dy)
{
// make sure lines get updated even if the view is empty
viewport()->update();
}
};
int main(int argc, char *argv[])
{
TreeWidget tree;
tree.show();
return app.exec();
}
#include <QtGui>
class TreeWidget : public QTreeWidget
{
public:
TreeWidget(QWidget* parent = 0) : QTreeWidget(parent)
{
setColumnCount(5);
}
protected:
void paintEvent(QPaintEvent* event)
{
QTreeWidget::paintEvent(event);
QPainter painter(viewport());
for (int i = 0; i < header()->count(); ++i)
{
// draw only visible sections starting from second column
if (header()->isSectionHidden(i) || header()->visualIndex(i) <= 0)
continue;
// position mapped to viewport
int pos = header()->sectionViewportPosition(i) - 1;
if (pos > 0)
painter.drawLine(QPoint(pos, 0), QPoint(pos, height()));
}
}
void scrollContentsBy(int dx, int dy)
{
QTreeWidget::scrollContentsBy(dx, dy);
// make sure lines get updated even if the view is empty
viewport()->update();
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TreeWidget tree;
tree.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
You could use for example QStyle::SH_Table_GridLineColor as pen color.
Bookmarks