I tried many times, and now i have this declaration:
class ListModel : public QAbstractListModel
{
Q_OBJECT
public:
ListModel
(QVector<QStringList>
&my2darray,
QObject *parent
= 0)
private:
QVector<QStringList> &vector;
};
{
Q_OBJECT
public:
ListModel(QVector<QStringList> &my2darray, QObject *parent = 0)
: QAbstractListModel(parent), vector(my2darray){}
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
private:
QVector<QStringList> &vector;
};
To copy to clipboard, switch view to plain text mode
I would like to know, what can i return as QVariant? Only strings? i need to return a custom_widget i created (it consists of 4 labels). I tried this code:
QVariant ListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
if (index.row() >= 20)
if (role == Qt::DisplayRole)
{
int a = index.row();
return Custom_Widget(vector[a][0], vector[a][1], vector[a][2], "");
}
else
}
{
if (!index.isValid())
return QVariant();
if (index.row() >= 20)
return QVariant();
if (role == Qt::DisplayRole)
{
int a = index.row();
return Custom_Widget(vector[a][0], vector[a][1], vector[a][2], "");
}
else
return QVariant();
}
To copy to clipboard, switch view to plain text mode
But it didn't worked. How should I alter my code to get it working?
Bookmarks