How do I get the "natural" widget size?
-
I'm trying to display a QLabel with its "natural" height but a custom width.
I've tried to get its height with w.height(), w.sizeHint().height() and w.normalGeometry().height().
The 1st is almost the height of the whole screen, the 2nd is just barely the height of the
text and doesn't seem to respect setContentMargins() and the 3rd returns 0.Thanks!
-
Hi reactive,
- w.height() should return the current height of the widget.
- w."sizeHint":http://doc.qt.nokia.com/latest/qwidget.html#sizeHint-prop () returns the size, the widget likes to have. This should be the content + perhaps border etc. It can be bigger than the content.
- w."minimumSizeHint":http://doc.qt.nokia.com/latest/qwidget.html#minimumSizeHint-prop () returns the minimum size, the widget wants to have to be able to display the content. It's always minimumSizeHint() <= sizeHint().
- "normalGeometry":http://doc.qt.nokia.com/latest/qwidget.html#normalGeometry-prop () makes no sense for non top level widgets
The margin should be taken into account for a QLabel for sizeHint and minimumSizeHint.
Afaik, setContentMargins is a function of the layout, not of the widget. This space is added between the widgets in the layout. See this "link":http://doc.qt.nokia.com/latest/qlayout.html#setContentsMargins .