Skip to content

Instantly share code, notes, and snippets.

@matrixd
Created March 6, 2017 22:15
Show Gist options
  • Select an option

  • Save matrixd/d5ee8f8a9ab51ecc12757c048bfa2c82 to your computer and use it in GitHub Desktop.

Select an option

Save matrixd/d5ee8f8a9ab51ecc12757c048bfa2c82 to your computer and use it in GitHub Desktop.
QTableView::resizeEvent(event);
int columns = this->model()->columnCount();
int totalHeaderWidth = 0;
for (int column = 0; column < columns; column++)
{
totalHeaderWidth += horizontalHeader()->sectionSizeHint(column);
}
//???
int availableWidth = event->size().width() - this->verticalOffset();
int freeSpace = availableWidth - totalHeaderWidth;
for (int column = 0; column < columns; column++)
{
int contentWidth = sizeHintForColumn(column);
int headerWidth = horizontalHeader()->sectionSizeHint(column);
int width = headerWidth;
if (freeSpace)
{
qreal stretchFactor = 1.0;
//get stretch factor based on content
stretchFactor = ((qreal)contentWidth)/((qreal)totalHeaderWidth);
width = stretchFactor * freeSpace + headerWidth;
qDebug() << stretchFactor << freeSpace << contentWidth << headerWidth << totalHeaderWidth;
}
setColumnWidth(column, width);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment