#include "form1.h"#include <qlistview.h>#include <qpixmap.h> #ifndef VYZF_H#define VYZF_Hclass MyQListViewItem : public QListViewItem{ public: MyQListViewItem( QListView *parent ); MyQListViewItem(QListViewItem * parent); MyQListViewItem( QListView * parent, QListViewItem * after ); MyQListViewItem( QListViewItem * parent, QListViewItem * after ); ~MyQListViewItem();public: virtual void paintCell( QPainter* p, const QColorGroup& cg, int column, int width, int align ); QColor color() const { return col; } QColor getColor() const {return col; }; void setColor( QColor c ) { col = c; }[b]#if !defined(Q_NO_USING_KEYWORD) using QListViewItem::setPixmap;#endif void setPixmap( int, QPixmap * p );private: QPixmap *pix;[/b]public: QColor col;};#endif // FORM1_H//.CPPvoid MyQListViewItem::setPixmap( int colum, QPixmap *px ){ pix = px; setup(); widthChanged( 0 ); invalidateHeight(); repaint();}
void Form1::addItem(){QPixmap * pix = new QPixmap (QPixmap::fromMimeSource( "Phone.png" )) ; MyQListViewItem * item; if ( on_menu_item ) item = new MyQListViewItem ( on_menu_item); else item = new MyQListViewItem ( listView2 ); int a = item->depth(); if ( item->depth() <2 ) { if ( item->depth() ==0 ) item ->setColor( "blue" ); item->setText( 0, "" ); item->setRenameEnabled( 0, true ); item->setOpen( true ); listView2->setCurrentItem( item ); item->startRename(0); [b] item->setPixmap( 0, pix); [/b] }
void MyQListViewItem::paintCell( QPainter* p, const QColorGroup& cg, int column, int width, int alignment ){ QColorGroup _cg( cg ); QColor c = _cg.text(); QPen pen = p->pen(); if(clr == "red" || clr == "blue" ){ QFont f( "Tahoma", 8, QFont::Bold ); p->setFont( f ); } _cg.setColor( QColorGroup::Text, clr ); QListViewItem::paintCell( p, _cg, column, width, alignment );}
QFEDirectory::QFEDirectory( QListView *tree, // parent object QTable *table, // friend object const QString& title, // tree item title const QString& path ) // start path : QListViewItem( tree ), FileName( path ), FileTable( table ){ // it is a first (root) item of tree Parent = 0; Path = path; // check can we read from this directory Readable = QDir( GetPath() ).isReadable(); setPixmap( FIRSTCOLUMN, XPM_Folder ); setText( FIRSTCOLUMN, title ); setExpandable( TRUE );}