Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set minimum height of QListWidgetItem?

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.

like image 282
daisy Avatar asked May 25 '12 02:05

daisy


2 Answers

Use setSizeHint on the items.

void QListWidgetItem::setSizeHint ( const QSize & size )

This is the right method for telling the delegate how much screen it must preserve for the item.

Look at http://qt-project.org/doc/qt-4.8/qlistwidgetitem.html#setSizeHint

like image 51
felixgaal Avatar answered Sep 19 '22 18:09

felixgaal


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..

like image 43
Ammar Avatar answered Sep 18 '22 18:09

Ammar