From this screenshot you can see a lot of space inside the rows:
I've used these functions to get resizing:
resizeRowsToContents();
resizeColumnsToContents();
How can I get a better fit for cells/rows sizes?
There seems to be a bug in Qt when you call resizeRowsToContents on the tableView of an empty table with a hidden verticalHeader, it does not accurately resize the rows. And considering that tables often start empty, this is a troublesome problem indeed. Fortunately I found a workaround on a qtcentre thread, as follows:
If table/model is not empty, use:
tableView->resizeRowsToContents();
const int rowHeight = tableView->verticalHeader()->sectionSize(0);
tableView->verticalHeader()->setDefaultSectionSize(rowHeight);
Otherwise, here is a workaround:
// workaround for Qt empty table auto-row-sizing problem
const int rowHeight = tableView->verticalHeader()->minimumSectionSize();
tableView->verticalHeader()->setDefaultSectionSize(rowHeight);
Try this:
void QHeaderView::setResizeMode(QHeaderView::ResizeToContents);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With