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 7083859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:13:49+00:00 2026-05-28T07:13:49+00:00

I have a problem with size calculation in Qt when adding new widgets at

  • 0

I have a problem with size calculation in Qt when adding new widgets at run time.
I have tried to illustrate the problem with the pruned program down there. Hopefully, it shows the same problem than my other (more complex) program:

When a widget has been shown, using:

w->show();

…and some new widgets are added to it later on (possibly w has a layout),
what should I do to redisplay w and its parents so that the size of the newly added child widgets is taken into account?
The behaviour I want is that the size recalculation propagates upward to the nearest scrolled object (or the main window if there is no scrolled objects)

In the example below, I create a little widget structure: if the call to show() (commented SHOW1) is removed, then the whole widget structure is defined before the first call to show() and everything works.
BUT: if I do call show() (at SHOW1), then the last show does not display the right things: the frame is still too small

 #include <QApplication>
 #include <QtCore>
 #include <QMainWindow>
 #include <QTabWidget>
 #include <QWidget>
 #include <QGroupBox>
 #include <QVBoxLayout>
 #include <QLabel>

 #include <stdlib.h>


 int main(int argc, char *argv[])
 {
    QApplication app(argc, argv);
    QMainWindow* main_window = new(QMainWindow);
    main_window->setObjectName("main_window");
    main_window->resize(800, 600);
    main_window->setWindowTitle("Hello");

    QTabWidget* node_tab_widget = new QTabWidget(main_window);
    node_tab_widget->setObjectName(QString::fromUtf8("tab_widget"));

    QWidget* w= new QWidget(node_tab_widget);
    node_tab_widget->addTab(w, "TAB");

    QGroupBox* group_widget = new QGroupBox("GROUPNAME", w);
    QVBoxLayout*  group_layout = new QVBoxLayout;
    group_widget->setLayout(group_layout);
    group_layout->addWidget((QLabel*)new QLabel(">>>>>>>>>>>>>>>>>>>>>>>>>here1"));

    main_window->show();  // SHOW1: If this one is commented, then OK!

    group_layout->addWidget((QLabel*)new QLabel("here2"));
    group_layout->addWidget((QLabel*)new QLabel("here2"));
    group_layout->addWidget((QLabel*)new QLabel("here2"));
    group_layout->addWidget((QLabel*)new QLabel("here2"));

    main_window->setCentralWidget(node_tab_widget);

    // main_window->update();
    // main_window->hide();

    main_window->show(); // How to I get that to recaclulate the size of its contents?
    return app.exec();
 }
  • 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-28T07:13:50+00:00Added an answer on May 28, 2026 at 7:13 am

    Your w widget doesn’t have a layout. Try adding the following lines after creating group_widget:

    QVBoxLayout *wlayout = new QVBoxLayout(w);
    wlayout->addWidget(group_widget);
    wlayout->addStretch();
    

    You can get rid of addStretch if you actually want w to span the entire parent.

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

Sidebar

Related Questions

I have a problem initializing an array whose size is defined as extern const.
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run
I had a problem with a program that uses MPI and I have just
I have a problem with setting new frame to uiview object. here is my
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for

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.