Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Without having the exact code, it's hard to say for sure, but having just attempted to reproduce your example, from the description above, I'd suggest looking at the following things:</p> <ol> <li><p>It sounds like you're actually calling <code>widget-&gt;height()</code> before the widget has been displayed. Instead, try calling <code>widget-&gt;sizeHint().height()</code> instead. The <a href="http://doc.qt.nokia.com/latest/qwidget.html#sizeHint-prop">QWidget::sizeHint()</a> method tells you what size the widget would <em>like to be</em>, if the parent geometry doesn't place any other constraints on it.</p></li> <li><p>If you're obtaining the <code>sizeHint()</code> and still getting the wrong answer, have a look at the documentation for <a href="http://doc.qt.nokia.com/latest/qwidget.html#ensurePolished">QWidget::ensurePolished()</a>. I believe that it's important to call this, to get more accurate geometries for widgets that have not yet been displayed:</p> <blockquote> <p>QWidget calls this function after it has been fully constructed but before it is shown the very first time. You can call this function if you want to ensure that the widget is polished before doing an operation, e.g., the correct font size might be needed in the widget's sizeHint() reimplementation.</p> </blockquote></li> <li><p>And if you're <em>still</em> having problems, then have a look at the documentation for <a href="http://doc.qt.nokia.com/latest/qwidget.html#sizePolicy-prop">QWidget::sizePolicy()</a>, and the class <a href="http://doc.qt.nokia.com/latest/qsizepolicy.html">QSizePolicy Class Reference</a>. I must admit that however many times I read the docs on <a href="http://QSizePolicy%3a%3aPolicy">enum QSizePolicy::Policy</a>, they never all sink in. It's really easy to have one incorrect size policy value mess up your layouts. </p> <p>It can be worth experimenting with the different size policies in Qt Designer, before actually applying a size policy.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload