Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
重新风格项代理QStyledItemDelegat

class QLineDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    QLineDelegate(QTableView
* tableView);
protected:
    
void paint(QPainter* painter,const QStyleOptionViewItem& option,const QModelIndex& index) const;
private:
    QPen         pen;
    QTableView
*  view;
};

#include <QPainter>
#include 
"QLineDelegate.h"

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
{
    QStyleOptionViewItem itemOption(option);
    
if(itemOption.state & QStyle::State_HasFocus)
        itemOption.state 
= itemOption.state ^ QStyle::State_HasFocus;
    QStyledItemDelegate::paint(painter,itemOption,index);
    QPen oldPen 
= painter->pen();
    painter
->setPen(pen);
    
//painter->drawLine(option.rect.topRight(),option.rect.bottomRight());
    painter->drawLine(itemOption.rect.bottomLeft(),itemOption.rect.bottomRight());
    painter
->setPen(oldPen);
}
posted on 2011-11-25 20:22 ccsdu2009 阅读(2553) 评论(0)  编辑 收藏 引用 所属分类: QT编程

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理