Fred
7th July 2014, 12:32
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.
QListWidget *widget = new QListWidget(this);
QFont font("Droid Sans", 12, false);
QFontMetrics fm(font);
int width = fm.width() * longestEntry + 10;
int height = fm.height() * widget.count() + 10;
widget->resize(width, height);
The problem is, that the space between the QListWidgetItems depends on the used font and QFontMetrics delivers only the height without the space.
http://img1.myimg.de/picture96a40_thumb.jpg (http://www.myimg.de/?img=picture96a40.jpg)
Is it possible to get these extra pixels so I can calculate the right height with
int height = (fm.height() + pixels) * widget.count();
Or is there another (better) way to resize the QListWidget to it's content?
Many thanks!
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.
QListWidget *widget = new QListWidget(this);
QFont font("Droid Sans", 12, false);
QFontMetrics fm(font);
int width = fm.width() * longestEntry + 10;
int height = fm.height() * widget.count() + 10;
widget->resize(width, height);
The problem is, that the space between the QListWidgetItems depends on the used font and QFontMetrics delivers only the height without the space.
http://img1.myimg.de/picture96a40_thumb.jpg (http://www.myimg.de/?img=picture96a40.jpg)
Is it possible to get these extra pixels so I can calculate the right height with
int height = (fm.height() + pixels) * widget.count();
Or is there another (better) way to resize the QListWidget to it's content?
Many thanks!