QListView with custom model and styleditem delegate
Solved
General and Desktop
-
Hi,
i have qlistview with a model and styled item delegate ,in my delegate i have overrieded sizehint() method,in which one parameter is qmodel index .is there any way to get my model object from qmodel index.my code is as follows
//list model for qlistview class MyListViewModel : public QAbstractListModel { Q_OBJECT public: MyListViewModel(std::vector<MyModel*>* modelList, QObject* parent = 0); int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role) const; std::vector<MyModel*>* m_pModelList; };
//MyModel.cpp class MyModel { public: MyModel(); MyModel(string name); ~MyModel(); string name; };
//delegate class MyDelegate : public QStyledItemDelegate { Q_OBJECT public: //enum datarole { Title = Qt::UserRole + 100, Start, Action, Stop }; MyDelegate(); ~MyDelegate(); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; static QSize iconSize; static int padding; };
//Mydelegate.cpp QSize Mydelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const { } void Mydelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { }
i want to know about how can i get MyModel object from qmodelindex inside sizeHint() and paint() method in MyDelegate
Jafar VM