I'm having a problem with code that worked in 4.2.3 not working in 4.3.0. I've pared it down to a simple test case.
The model inherits QAbstractTableModel. relevant code:
Qt
::ItemFlags TestModel
::flags(const QModelIndex &index
) const{
if (index.row() == column1_.count() && index.column() != 0)
else
}
int TestModel::rowCount(const QModelIndex&) const
{
return column1_.count() + 1;
}
QVariant TestModel
::data(const QModelIndex
& index,
int role
) const {
if (!index.isValid() || role != Qt::DisplayRole)
else if (index.row() == column1_.size())
else if (index.column() == 0)
return column1_.at(index.row());
else
return column2_.at(index.row());
}
{
if (!index.isValid() || role != Qt::EditRole)
return false;
if (index.row() == column1_.size())
{
if (index.column() != 0)
return false;
else
{
column1_ << value.toString();
emit layoutChanged();
return true;
}
}
else
{
if (index.column() == 0)
column1_[index.row()] = value.toString();
else
column2_[index.row()] = value.toString();
emit dataChanged(index, index);
return true;
}
}
Qt::ItemFlags TestModel::flags(const QModelIndex &index) const
{
if (index.row() == column1_.count() && index.column() != 0)
return QAbstractTableModel::flags(index);
else
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
}
int TestModel::rowCount(const QModelIndex&) const
{
return column1_.count() + 1;
}
QVariant TestModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid() || role != Qt::DisplayRole)
return QVariant();
else if (index.row() == column1_.size())
return QVariant();
else if (index.column() == 0)
return column1_.at(index.row());
else
return column2_.at(index.row());
}
bool TestModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid() || role != Qt::EditRole)
return false;
if (index.row() == column1_.size())
{
if (index.column() != 0)
return false;
else
{
column1_ << value.toString();
column2_ << QString();
emit layoutChanged();
return true;
}
}
else
{
if (index.column() == 0)
column1_[index.row()] = value.toString();
else
column2_[index.row()] = value.toString();
emit dataChanged(index, index);
return true;
}
}
To copy to clipboard, switch view to plain text mode
I'm using QTableViewfor the view.
In 4.2.3, when I enter data in the last row in column 1, a new row immediately appears immediately below the last row (see rowCount function). In 4.3.0, no new row appears, event though I'm emitting layoutChanged(). Is there something I'm missing and 4.2.3 let me get by?
Any help would be very much appreciated.
Bookmarks