[Interest] Proxy model prepending rows to model

Clément Geiger clement.geiger at gmail.com
Wed Oct 23 11:07:23 CEST 2013


Hi,

I have a base model, a table with two columns and a bunch of rows.

To display it in a QComboBox, I'm using a proxy model that merges the two
columns in one.

>From there on I thought it would be cool to a row on top of everything
saying "<Select Stuff>".

So I did that in the ProxyModel:


int ServicesListProxyModel::rowCount(QModelIndex const &) const
{
  return model()->rowCount() + 1;
}

// ...

QVariant ServicesListProxyModel::data(QModelIndex const & index, int role)
{
  if(index.row() == 0)
    return tr("Select a service");

  QModelIndex sourceId = model()->index(index.row() - 1,
ServicesListModel::Column_ID);
  QModelIndex sourceName = model()->index(index.row() - 1,
QiServicesListModel::Column_Name);

  // return the normal line of text agregating id and name
}

It works nicely, however I get this in the console output:

QAbstractItemModel::endInsertRows: Invalid index ( 79 , 0 ) in model
QProxyModel(0xad8050)


Am I missing something obvious here ?


Thanks a bunch in advance :)


Clément
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131023/09901b56/attachment.html>


More information about the Interest mailing list