How to set minimum height of QListWidgetItem?
Asked Answered
H

2

9

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.

Halden answered 25/5, 2012 at 2:30 Comment(0)
M
12

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

Mun answered 25/5, 2012 at 6:14 Comment(1)
i saw setSizeHint but didn't expect that its the soltuionBetteanne
P
15

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

Puccini answered 25/5, 2012 at 6:11 Comment(0)
M
12

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

Mun answered 25/5, 2012 at 6:14 Comment(1)
i saw setSizeHint but didn't expect that its the soltuionBetteanne

© 2022 - 2024 — McMap. All rights reserved.