Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QTableWidget::resizeRowsToContents() doesn't work until user's manual action
sm.sabat last edited by
I populate my QTableWidget with ComboBoxes:
w = new QWidget; ui->tableWidget->setCellWidget(row, col, w); lay = new QHBoxLayout(w); w->setLayout(lay); box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); lay->addWidget(box, 0, Qt::AlignCenter);
I call this function several times before I show QTableWidget to the user, and before that I do:
ui->tableWidget->resizeColumnsToContents(); ui->tableWidget->resizeRowsToContents(); ui->tableWidget->horizontalHeader()->setStretchLastSection(true); ui->tableWidget->repaint();
QComboBoxes are visible in full and rows are a little wider than default (as to be expected). Now I call the functions again (with user looking) and the newly added row is stuck on default height (so it's too narrow for QComboBox to look good). After user clicks the vertical header, the row instantly snaps into the correct height fixing the visibility problem. What can I do to force QTableWidget to do this automatically?
Ratzz last edited by
Can you try
Maybe this is related to https://bugreports.qt.io/browse/QTBUG-69563 ? But this only affects 5.11 and up.