Hi, I need to calculate max number of items in current view of QListView. I've wrote code like this:
{
qDebug()<<"QListView spacing: " <<this->spacing(); //its 0
qDebug()<<"column: " << this->modelColumn(); //its 0
int fontHeight = fm.lineSpacing();
QRect cr
= contentsRect
();
int windowHeight = cr.bottom() - cr.top();
int maxItemsCount = windowHeight / fontHeight;
qDebug()<<"max items in view: "<< maxItemsCount; //incorrect :( why?
}
void MyListView::resizeEvent(QResizeEvent *event)
{
QListView::resizeEvent(event);
qDebug()<<"QListView spacing: " <<this->spacing(); //its 0
qDebug()<<"column: " << this->modelColumn(); //its 0
QFontMetrics fm (this->font());
int fontHeight = fm.lineSpacing();
QRect cr = contentsRect();
int windowHeight = cr.bottom() - cr.top();
int maxItemsCount = windowHeight / fontHeight;
qDebug()<<"max items in view: "<< maxItemsCount; //incorrect :( why?
}
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?
Bookmarks