View Full Version : Determining the height of an item in a QListWidget
negritot
11th May 2009, 23: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, 04:57
Using visualRect (http://doc.qtsoftware.com/4.5/qabstractitemview.html#visualRect) you can determine the height.
talk2amulya
12th May 2009, 14:13
or you can directly go for QListWidget::visualItemRect(QListWidgetItem);
negritot
12th May 2009, 20: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, 05:46
How did you call QAbstractItemView::visualRect ???
negritot
13th May 2009, 19: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;
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.