Adding Vertical headers to a QTreeView

核能气质少年 提交于 2019-12-04 12:38:59

Your probably right that you will have to "pretend" but you should be able to draw it to look as good as your horizontal headers.

What you need to do is be in charge of the paintEvent for those cells and then use the current style to draw a custom control. Something like:

//QWidget* w is the widget who's style you want
QPainter painter(this);
QStyleOptionHeader opt;
opt.initFrom(this);
opt.state = QStyle::State_None;
opt.orientation = Qt::Vertical;
opt.state |= QStyle::State_Vertical;
if (w->isEnabled())
    opt.state |= QStyle::State_Enabled;
opt.state |= QStyle::State_Active;
w->style()->drawControl(QStyle::CE_Header, &opt, &painter, w);

The easiest way to be in charge of a paint event for the cells you want would be to create a custom item delegate and reimplement the virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const = 0 method. You just gate your painting to the indexes you care about and pass the rest to the super class (see Qt's docs for this class).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!