Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Adjust QListWidget size to content
smnsmn last edited by
I've been trying to adjust the size of QListWidget to its contents (QListWidgetItems with text); solutions found in google either complicated (in my opinion) for such a trivial task or given little to no explanation or code snippets. I guess there's an easy and elegant solution but still have no clue.
Thanks in advance.
One possible source of information is QListWidget::sizeHintForColumn. You can use that to resize your widget.
smnsmn last edited by smnsmn
Here's the code snippet in case anyone's looking for an answer:
ui->listWidget->setFixedSize(ui->listWidget->sizeHintForColumn(0) + ui->listWidget->frameWidth() * 2, ui->listWidget->sizeHintForRow(0) * ui->listWidget->count() + 2 * ui->listWidget->frameWidth());