Hi,

I'm trying to resize a QListWidget to it's content with QFontMetrics, calculating the height and the width. The calculating of the width works perfectly, but it fails to calculate the right height.

Qt Code:
  1. QListWidget *widget = new QListWidget(this);
  2. QFont font("Droid Sans", 12, false);
  3. QFontMetrics fm(font);
  4.  
  5. int width = fm.width() * longestEntry + 10;
  6. int height = fm.height() * widget.count() + 10;
  7.  
  8. widget->resize(width, height);
To copy to clipboard, switch view to plain text mode 
The problem is, that the space between the QListWidgetItems depends on the used font and QFontMetrics delivers only the height without the space.


Is it possible to get these extra pixels so I can calculate the right height with
Qt Code:
  1. int height = (fm.height() + pixels) * widget.count();
To copy to clipboard, switch view to plain text mode 

Or is there another (better) way to resize the QListWidget to it's content?

Many thanks!