开发者

QTableView has unwanted checkboxes in every cell

开发者 https://www.devze.com 2022-12-22 16:56 出处:网络
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

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:

QTableView has unwanted checkboxes in every cell

(source: nerdland.net)

What in the heck are thos开发者_运维问答e 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.


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.


Do you by any chance happen to set the Qt::ItemIsUserCheckable flag in flags()?

0

精彩评论

暂无评论...
验证码 换一张
取 消