Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6570761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:47:48+00:00 2026-05-25T14:47:48+00:00

I have a widget to insert that looks like this +——————–+ | +——-++——-+ |

  • 0

I have a widget to insert that looks like this

+--------------------+
| +-------++-------+ |
| |       ||       | |
| |       ||       | |
| |       || Label | |
| | Label || Label | |
| |       ||       | |
| |       ||       | |
| +-------++-------+ |
+--------------------+

A QWidget element containing two QVBoxLayouts, each containing one or more QLabels.
This Widget is going to be inserted in a Vertical Layout that has a stretch cell, so all the widgets of this kind will go to the top and shrink to the smaller height possible.

Resulting in something like this.

______________________ ← Layout boundary
+--------------------+
| +-------++-------+ |
| |       || Label | |
| | Label || Label | | ← Widget shrunk to the smallest
| +-------++-------+ |
+--------------------+
______________________ ← Layout boundary
          ↑
          |
          | ← Spacer
          |
          ↓
______________________ ← Layout boundary

But before doing this insert, I want to know the size that the widget would have in the inserted layout. Maybe the minimum size allowed by its internal layout. Not sure how to call it.

I have tried already many approaches like inserting the widget in an alternate invisible layout so I can retrieve its height when inserted, which should be the same that the widget would take when inserted in my definitive layout.

But for some reason I always get 480 or 478 when the widget is at most 50px height when pressed vertically. So I am totally lost.

I have to do this because I need the widget to animate when inserting, and I need to know the height it will take for me to animate from height 1 to it.

How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:47:48+00:00Added an answer on May 25, 2026 at 2:47 pm

    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:

    1. It sounds like you’re actually calling widget->height() before the widget has been displayed. Instead, try calling widget->sizeHint().height() instead. The QWidget::sizeHint() method tells you what size the widget would like to be, if the parent geometry doesn’t place any other constraints on it.

    2. If you’re obtaining the sizeHint() and still getting the wrong answer, have a look at the documentation for QWidget::ensurePolished(). I believe that it’s important to call this, to get more accurate geometries for widgets that have not yet been displayed:

      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.

    3. And if you’re still having problems, then have a look at the documentation for QWidget::sizePolicy(), and the class QSizePolicy Class Reference. I must admit that however many times I read the docs on enum QSizePolicy::Policy, they never all sink in. It’s really easy to have one incorrect size policy value mess up your layouts.

      It can be worth experimenting with the different size policies in Qt Designer, before actually applying a size policy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little web app that uses the Facebook like widget. This page
I have a form that makes an Ajax POST request to insert a widget
I have a widget that acts as a launcher on the home screen. How
I have this widget: $this->setWidget('slug', new sfWidgetFormDoctrineChoice(array('model' => 'MyTable', 'method' => 'myMethod', 'key_method' =>
I have a widget that supposed to call an Activity of the main app
Let's say that I have a widget that displays summary information about how many
I am using a fictional example for this. Say, I have a Widget class
I have a UI widget that needs to be put in an IFRAME both
We have a UI widget on our main UI that uses JavaScript to respond
I have a TextEdit widget in PyQt that I use to print out a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.