代码如下:
#ifndef _CLASSIFYLISTWIDGET_H_
#define _CLASSIFYLISTWIDGET_H_ #include <QtGui> class ClassifyListalbum; class ClassifyListItem; class ClassifyListWidget : public QListWidget { Q_OBJECT public: ClassifyListWidget(QWidget* parent); void addTopItem(ClassifyListalbum* item); int getTopItemRow(ClassifyListalbum* album); bool isTopItem(ClassifyListalbum* album); public slots: void classifyitemClicked(QListWidgetItem *item); void currentItemChangedSlot(QListWidgetItem *current, QListWidgetItem *previous); protected: private: QList<ClassifyListalbum*> m_topLevelItems; QListWidgetItem* m_currentItem; }; class ClassifyListalbum : public QListWidgetItem { public: ClassifyListalbum(QListWidget* parent = NULL); public: void expandItem(); void collapseItem(); void addchild(ClassifyListItem* item); int childcount(); bool isExpanded(); ClassifyListItem* child(int i); private: QList<ClassifyListItem*> m_children; bool m_bExpanded; bool m_bIsSelected; }; class ClassifyListItem : public QListWidgetItem { public: ClassifyListItem(QListWidget* parent = NULL); public: bool getExpanded(); void setSel(bool sel); private: bool m_bExpanded; bool m_bIsSelected; }; class playlistdelegate : public QItemDelegate { Q_OBJECT public: /** * @brief This only passes throught ot the QItemdelegate-Constructor */ playlistdelegate(QObject *parent); /** *@brief This does the paint of the text on two lines if there is a <br> in the text */ void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; }; #endif