Created
March 6, 2017 22:15
-
-
Save matrixd/d5ee8f8a9ab51ecc12757c048bfa2c82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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