How to set minimum height of QListWidgetItem?

允我心安 提交于 2019-12-23 07:33:27

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/10747752/how-to-set-minimum-height-of-qlistwidgetitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!