首页| 论坛| 消息

标题:如何改变QTreeView中header以及内容的对齐方式
作者:mj1232
日期:2010-12-03 19:08
内容:

我用QTreeView造了表,我想把表中头部的某一项及其该项对应的列进行右对齐(就是改变该表header的其中一项对齐方式),请问如何实现?


#1 [apple_2006 06-14 15:29]
model()->setHeaderData(列号, Qt::Horizontal, (int)(Qt::AlignRight|Qt::AlignVCenter), Qt::TextAlignmentRole );
可以试一下
#2 [年轻还有几年 03-09 20:02]
楼主解决了吗
#3 [kimtaikee 03-10 11:30]
从我的项目中截一段代码:
QVariant XXXModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if (orientation == Qt::Horizontal && role == Qt::TextAlignmentRole)
        return QVariant(Qt::AlignTop | Qt::AlignHCenter);
    if (orientation == Qt::Vertical && role == Qt::TextAlignmentRole)
        return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
    return QAbstractTableModel::headerData(section, orientation, role);
}
效果如下图,就是横向表头的文字居顶加横向居中,竖向表头的文字居左加竖直居中。

回复 发表
主题 版块