[Qt-interest] QTableView and spans

Stephen Kelly steveire at gmail.com
Thu Aug 13 08:04:35 CEST 2009


Lars Amsel wrote:

> Alex,
> 
> as Stephen stated there is already a method called span in the
> QAbstractItemModel, but it is not used so far (I tried with Qt 4.5.2).
> 
> At the end of the day I have a structure with a top level and exactly one
> child level.
> 
> One way would be to implement the model like any other with indefinite
> depth. But then things get complicated on the view side. Display this
> structure with spans on a table view means rewriting the QTableView.
> On the other hand I could write a model that presents the data in a flat
> view as QAbstractTable model. But that makes the model ugly to read and
> furthermore I still have to set the spans on the view side.
> 
> I was hoping that I have overseen an easy solution, but obviously there
> isn't such a solution.

Another very ugly hack might be to create your own delegate and use it for 
the items which should span.

MyDelegate::sizeHint ( ... )
{
  QSize superSize = QItemDelegate::sizeHint(...);
  int N = index.data(SpanRole).toInt();

  if (spanRole > 1)
    superSize.setHeight(superSize() * N );

  return superSize;
}



I don't know if it would work.

Steve.


> 
> regards
> 
> Lars




More information about the Qt-interest-old mailing list