QTableView has unwanted checkboxes in every cell
c++, qabstractitemmodel, qt, qtableview, qtwidgets
Solution
Try changing `MyTableModel::data()` to the following:
QVariant MyTableModel::data(const QModelIndex& index, int role) const
{
if (role == Qt::DisplayRole)
return "foo";
else
return QVariant();
}
Probably the returned QVariant for role `Qt::CheckStateRole` was misunderstood by the QTableView.
Problem
I'm trying to make a simple tabular data layout using a `QTableView` with a model class of my own creation inheriting from `QAbstractTableModel`. For some reason, my table view ends up looking like this: (source: nerdland.net) What in the heck are those things that look like checkboxes (but don't do anything when I click them) in every cell, and how do I make them go away? I haven't changed any of the `QTableView` properties except for the object's name. If it matters, my model code is dead simple: ``` MyTableModel::MyTableModel(QObject* parent) : QAbstractTableModel(parent) { } MyTableModel::~MyTableModel() { } int MyTableModel::rowCount(const QModelIndex& parent) const { return 1000; } int MyTableModel::columnCount(const QModelIndex& parent) const { return 5; } QVariant MyTableModel::data(const QModelIndex& index, int role) const { return "Foo"; } ``` The dialog UI is built in Qt Designer, and inside the class for the dialog I attach the model to the view like this: ``` MyTableModel testModel = new MyTableModel(this); ui.testTable->setModel(testModel); ``` Other than that, I perform no operations on `ui.testTable`. Using Qt 4.6.