I was able to accomplish this in 2 parts.
First, I implemented span() for my model, which would look something like this:
if(isSpanningColumn(index)) {
return QSize(spanAmount,
1);
}
}
QSize MyModel::span(QModelIndex index) {
if(isSpanningColumn(index)) {
return QSize(spanAmount, 1);
}
return QSize(1, 1);
}
To copy to clipboard, switch view to plain text mode
Then I reimplemented the setModel() method in my view:
for(int col = 0; col < model->columnCount(); col++){
for (int row = 0; row < model->rowCount(); row++){
QSize span
= model
->span
(model
->index
(row, col
));
if(span
!= QSize(1,
1)) //Preform this check so you don't get a bunch of warnings about setting a span of 1 being ignored setSpan(row, col, span.height(), span.width());
}
}
}
void MyTableView::setModel(QAbstractItemModel* model){
QTableView::setModel(model);
for(int col = 0; col < model->columnCount(); col++){
for (int row = 0; row < model->rowCount(); row++){
QSize span = model->span(model->index(row, col));
if(span != QSize(1,1)) //Preform this check so you don't get a bunch of warnings about setting a span of 1 being ignored
setSpan(row, col, span.height(), span.width());
}
}
}
To copy to clipboard, switch view to plain text mode
I hope that helps
Bookmarks