www.pudn.com > treeView.rar > tree.cpp, change:2011-03-12,size:1554b


#include "tree.h" 
#include <QPainter> 
#include <QApplication> 
Tree::Tree() 
{ 
    model = new QStandardItemModel(4,1); 
    model->setHeaderData(0, Qt::Horizontal, tr("我的联系人")); 
 
 //   qApp->setStyleSheet("QListView::item{ height:35  px;} "); 
    QStandardItem *item1 = new QStandardItem("avahi-daemon"); 
           item1->setIcon(QIcon("gparted.png")); 
           QStandardItem *item2 = new QStandardItem("bluetooth"); 
           item2->setIcon(QIcon("gparted.png")); 
           QStandardItem *item3 = new QStandardItem("crond"); 
           QStandardItem *item4 = new QStandardItem("cups"); 
           model->setItem(0, 0, item1); 
           model->setItem(1, 0, item2); 
           model->setItem(2, 0, item3); 
           model->setItem(3, 0, item4); 
   QStandardItem *item5 = new QStandardItem("fifth"); 
   item1->appendRow(item5); 
 
    setModel(model); 
    setSelection(QRect(220,220,300,300),QItemSelectionModel::Toggle); 
    setSelectionMode(QAbstractItemView::SingleSelection); 
} 
void Tree::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const 
{ 
    //painter->drawPixmap(0,0,QPixmap("1000.jpg")); 
  //  rect.adjusted(-50,-50,50,50); 
 
 
//    QTreeView::drawRow( painter, rect, index ); 
} 
void Tree::drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const 
{ 
    QPixmap p("1000.jpg"); 
    painter->drawPixmap( options.rect.topLeft().x(), options.rect.topLeft().y(),p.scaled(20,20)); 
    QTreeView::drawRow( painter, options, index ); 
}