www.pudn.com > treeView.rar > listview.cpp, change:2011-03-13,size:1481b


#include "listview.h" 
#include <QDebug> 
#include <itemdelegate.h> 
ListView::ListView(QWidget *parent) : 
    QListView(parent) 
{ 
    model = new QStandardItemModel(4,2  );     
    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->setSizeHint(QSize(40,40)); 
 
   connect(this,SIGNAL(clicked(QModelIndex)),SLOT(itemClicked(QModelIndex))); 
   item1->appendRow(item5); 
   item5->parent()->setEnabled(false); 
   ItemDelegate *dele = new ItemDelegate; 
//   setItemDelegate(dele); 
    setModel(model); 
   setBatchSize(1000); 
   //setSpacing(100); 
   setContentsMargins(20,02,20,02); 
   setFrameRect(QRect(10,10,10,10)); 
} 
void ListView::itemClicked(QModelIndex index) 
{ 
    setRowHidden(1,true); 
    setRowHidden(2,true); 
 
    qDebug()<<"hide"; 
}