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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:59:32+00:00 2026-06-16T03:59:32+00:00

I’m having extreme trouble getting QWidgets to expand as needed. This isn’t the first

  • 0

I’m having extreme trouble getting QWidgets to expand as needed. This isn’t the first time I’ve run into this problem, and last time I solved it by hacking in a large sizeHint(). This is the WRONG approach and I would really like to learn the CORRECT approach.

If anyone could help me out it would be greatly appreciated. Here’s what it looks like and the layouts I have written in code. If necessary I can supply the code. Please help me learn Layouts.

Edit: The first layout mock up actually works correctly. I am attaching another layout mockup which causes a problem.

Example Of Resizing


Mock Up of the Layouts


Breaks Expansion


Code. Three classes.

MainWindow Class:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    QWidget * w = new MainCentralWidget(this);
    setCentralWidget(w);
}

MainCentralWidget Class:

MainCentralWidget::MainCentralWidget(QWidget *parent) :
    QWidget(parent)
{
    SetupLayout();
}

void MainCentralWidget::SetupLayout()
{
    QVBoxLayout * main_layout;
    QFormLayout * plugin_layout;

    //Start
    main_layout = new QVBoxLayout();

    //Setup the plugin chooser
    plugin_layout = new QFormLayout();
    QComboBox * plugins_box = new QComboBox();

    plugin_layout->addRow("Choose Plugin: ", plugins_box);

    QFrame* line = new QFrame();
    line->setFrameShape(QFrame::HLine);
    line->setFrameShadow(QFrame::Sunken);
    plugin_layout->addRow(line);

    main_layout->insertLayout(0, plugin_layout);

    main_layout->insertWidget(1, new SubWidget());

    //Finish
    setLayout(main_layout);

    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}

SubWidget Class:

SubWidget::SubWidget(QWidget *parent) :
    QWidget(parent)
{
    setStyleSheet("QWidget { background: yellow }");

    setMaximumSize(10000,10000);
    setMinimumSize(100,100);
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    SetupLayout();


    //setMaximumSize(10000,10000);
}

void SubWidget::SetupLayout()
{
    QHBoxLayout main_layout;

    main_layout.setAlignment(Qt::AlignTop | Qt::AlignLeft);
    main_layout.addWidget(&m_graphics_view);
    m_graphics_view.setMaximumSize(10000,100000);

    setLayout(&main_layout);
}
  • 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-06-16T03:59:33+00:00Added an answer on June 16, 2026 at 3:59 am
    void SubWidget::SetupLayout()
    {
        QHBoxLayout main_layout;
    
        main_layout.setAlignment(Qt::AlignTop | Qt::AlignLeft);
        main_layout.addWidget(&m_graphics_view);
        m_graphics_view.setMaximumSize(10000,100000);
    
        setLayout(&main_layout);
    }
    

    Your main_layout gets destroyed immediately after SetupLayout finished, as it goes out of scope. So, actually, your SubWidget has no any layout. That is why widgets are shown incorrectly.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am currently running into a problem where an element is coming back from
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.