Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTableView has unwanted checkboxes in every cell

I'm just getting started with Qt programming, and I'm trying to make a simple tabular data layout using a QTableView control with a model class of my own creation inheriting from QAbstractTableModel. For some reason, my table view ends up looking like this:

alt text
(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.

like image 837
Tyler McHenry Avatar asked Mar 07 '10 15:03

Tyler McHenry


1 Answers

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.

like image 157
Elrohir Avatar answered Sep 28 '22 16:09

Elrohir