Hello everyone,
I'm having a difficult time getting a table set up. I subclassed QAbstractTableModel as such:
int FileModel
::rowCount(const QModelIndex &parent
) const {
return files.count();
}
int FileModel
::columnCount(const QModelIndex &parent
) const { return 4;
}
printf("row %d\n",(int)index.row());
if (!index.isValid())
if (index.row() >= files.size())
if (role == Qt::DisplayRole) {
printf("%s\n",files.value(file_list.at(index.row()))->m_path.c_str());
return QString(files.
value(file_list.
at(index.
row()))->m_path.
c_str());
} else {
}
}
int FileModel::rowCount(const QModelIndex &parent) const {
return files.count();
}
int FileModel::columnCount(const QModelIndex &parent) const {
return 4;
}
QVariant FileModel::data(const QModelIndex &index, int role) const {
printf("row %d\n",(int)index.row());
if (!index.isValid())
return QVariant();
if (index.row() >= files.size())
return QVariant();
if (role == Qt::DisplayRole) {
printf("%s\n",files.value(file_list.at(index.row()))->m_path.c_str());
return QString(files.value(file_list.at(index.row()))->m_path.c_str());
} else {
return QVariant();
}
}
To copy to clipboard, switch view to plain text mode
I set the model in a view like this:
FileModel fmodel;
table->setModel(&fmodel);
table->setAlternatingRowColors(true);
table->show();
FileModel fmodel;
QTableView *table = new QTableView(this);
table->setModel(&fmodel);
table->setAlternatingRowColors(true);
table->show();
To copy to clipboard, switch view to plain text mode
However, an empty table shows up with the correct number of rows and columns. I'm not sure why this is happening and I've tried just about everything I can think of.
Any ideas?
Thanks!
Bookmarks