[SOLVED] Checkbox added to QStandardItem with setCheckable(false) ?
-
Dear fellow programmers,
I worked on a simple QTableView example that uses custom data (using a derived class of QStandardItemModel). The (downsized) core is to implement a QStandardItemModel that displays a custom data type with a std::vectorstd::string.
[code]
struct MyModel : public QStandardItemModel
{
MyModel(/* /)
{
for (int i=0; i!=/ /; ++i)
{
QList<QStandardItem> items;
//Add text
{
QStandardItem * const item = new QStandardItem;
item->setCheckable(false); //NO CHECKBOX!
items.push_back(item);
}
//Only have one column for now
assert(this->columnCount() == items.size());
this->appendRow(items);
}
}
}
[/code]Although I explicity setCheckable to false, when I view my application, it does show checkboxes.
What did I miss?
Full code (including screenshot and full Qt Project download) at http://www.richelbilderbeek.nl/CppQTableViewExample5.htm
Thanks, Bilderbikkel
-
Solved! The cause was not in the code posted, but in MyModel::data:
[code]
struct MyModel : public QStandardItemModel
{
///Implement virtual member function
QVariant data(const QModelIndex &index, int role) const
{
//Removing this line will cause checkboxes to appear
if (role != Qt::EditRole && role != Qt::DisplayRole) return QVariant();//Work on data
}
};
[/code]Good luck with this answer B-)