justinleona

30th September 2009, 23:28

I have a heirarchical model which has different numbers of columns per teir, but I haven't figured out a way to get QTreeView to show the maximum number of columns without faking the maximum at the root level.

This is essentially what my columnCount looks like:

//Returns the number of columns for the children of the given parent

int Model::columnCount(const QModelIndex &index) const {

if( index.isValid() )

return 6;

return 1;

}

Initially the model is empty - so the table has 1 column and no rows.

I am resetting the model after adding data, which populates the TreeView with 1 first-tier entry and a few hundred second-tier entries, but the TreeView is still fixed at 1 column.

While its possible to do per-entry beginInsertRows/endInsertRows and beginInsertColumns/endInsertColumns, I don't know if this would help - and it would be complex due to the nature of the data.

Now if I changed the columnCount to always return 6 - then the table shows all the columns all the time, but I think this is really a hack - the 1st tier items don't have valid indices for columns 1-5.

Any suggestions?

Justin

This is essentially what my columnCount looks like:

//Returns the number of columns for the children of the given parent

int Model::columnCount(const QModelIndex &index) const {

if( index.isValid() )

return 6;

return 1;

}

Initially the model is empty - so the table has 1 column and no rows.

I am resetting the model after adding data, which populates the TreeView with 1 first-tier entry and a few hundred second-tier entries, but the TreeView is still fixed at 1 column.

While its possible to do per-entry beginInsertRows/endInsertRows and beginInsertColumns/endInsertColumns, I don't know if this would help - and it would be complex due to the nature of the data.

Now if I changed the columnCount to always return 6 - then the table shows all the columns all the time, but I think this is really a hack - the 1st tier items don't have valid indices for columns 1-5.

Any suggestions?

Justin