PDA

View Full Version : Determining the height of an item in a QListWidget



negritot
12th May 2009, 00:04
How can I determine the height of a single item in a QListWidget? I'm looking for the equivalent of Q3ListBox::itemHeight, or MFC's CListBox::GetItemHeight:

http://msdn.microsoft.com/en-us/library/d5804hcf.aspx

munna
12th May 2009, 05:57
Using visualRect (http://doc.qtsoftware.com/4.5/qabstractitemview.html#visualRect) you can determine the height.

talk2amulya
12th May 2009, 15:13
or you can directly go for QListWidget::visualItemRect(QListWidgetItem);

negritot
12th May 2009, 21:31
Thanks guys! QListWidget::visualItemRect worked, but the more generic QAbstractItemView::visualRect returned a height of zero. I'm not sure why there's a discrepancy. :confused:

aamer4yu
13th May 2009, 06:46
How did you call QAbstractItemView::visualRect ???

negritot
13th May 2009, 20:18
Now that I try it again, it works.



QRect itemRect1 = listWidget.visualItemRect(listWidget.item(0));
QRect itemRect2 = listWidget.visualRect(listWidget.model()->index(0, 0));

At the end itemRect1 == itemRect2;