How to set minimum height of QListWidgetItem?

daisy picture daisy · May 25, 2012 · Viewed 18k times · Source

How can I set the minimum height of a QListWidgetItem? I'm using QListWidget::setItemWidget() with a customized widget, and although I explicitly declared minimum height of my customized widget, those QListWidgetItems still have a pretty low height attribute.

Answer

Ammar picture Ammar · May 25, 2012

To set minimum height of each individual QListWidgetItem you can use sizeHint() function. For example, following code will set minimum height of all the QListWidgetItem to 30px..

int count = ui->listWidget->count();
for(int i = 0; i < count; i++)
{
  QListWidgetItem *item = ui->listWidget->item(i);
  item->setSizeHint(QSize(item->sizeHint().width(), 30));
}

Hope this helps..