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:

Qt Code:
  1. //Returns the number of columns for the children of the given parent
  2. int Model::columnCount(const QModelIndex &index) const {
  3. if( index.isValid() )
  4. return 6;
  5. return 1;
  6. }
To copy to clipboard, switch view to plain text mode 

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