Hi, I need to calculate max number of items in current view of QListView. I've wrote code like this:

Qt Code:
  1. void MyListView::resizeEvent(QResizeEvent *event)
  2. {
  3. QListView::resizeEvent(event);
  4. qDebug()<<"QListView spacing: " <<this->spacing(); //its 0
  5. qDebug()<<"column: " << this->modelColumn(); //its 0
  6.  
  7. QFontMetrics fm (this->font());
  8. int fontHeight = fm.lineSpacing();
  9.  
  10. QRect cr = contentsRect();
  11. int windowHeight = cr.bottom() - cr.top();
  12.  
  13. int maxItemsCount = windowHeight / fontHeight;
  14. qDebug()<<"max items in view: "<< maxItemsCount; //incorrect :( why?
  15.  
  16.  
  17. }
To copy to clipboard, switch view to plain text mode 

but calculated max number of items is is incorrect. E.g. in case of my window height and font height I get 32 items when in fact current view has 28 items max. Perhaps someone can suggest something, how to calculate it properly?