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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:54:23+00:00 2026-06-15T21:54:23+00:00

I would like to force an expanding space in my QFormLayout , but no

  • 0

I would like to force an expanding space in my QFormLayout, but no matter what QFormLayout only uses the QSpaceItem::sizeHint(). Does anyone know a way around this, or the proper way to handle this?


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

void MyWidget::SetupLayout()
{
   QFormLayout * layout = new QFormLayout();

   layout->addRow("Something1", new QComboBox());
   layout->addRow("Something2", new QSpinBox());

   //Spacer
   layout->addItem(new QSpacerItem(0,10, QSizePolicy::Expanding, QSizePolicy::Expanding));

   layout->addRow(QPushButton("Something3"));

   setLayout(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-15T21:54:24+00:00Added an answer on June 15, 2026 at 9:54 pm

    So there were a few different issues:

    1. QFormLayout do not expand like other layouts. My widgets (a few of them) were being placed into a QFormLayout. This prevented them from expanding. I switched my main parent layout from QFormLayout to QVBoxLayout. This made me have to use QLayout::setAlignment(Qt::AlignTop)
    2. This fixed a few problems with a few of my other widgets not expanding. However these widgets used QVBoxLayout. The widget above uses a QFormLayout. To get this expand, I had to use the following line in my QSpacerItem:

    QSpacerItem * my_spacer = new QSpacerItem(0,1000, QSizePolicy::Expanding, QSizePolicy::Expanding);


    I am supplying some example code. The goal is to show the hierarchy, and where QFormLayout would cause trouble.

    Example code:

    //A main Widget class
    void SetupLayout()
    {
       QHBoxLayout * main_layout = new QHBoxLayout();
    
       main_layout->addWidget(Some_Widget);
    
       //Create a control widget
       control_widget = new QWidget();  // IMPORTANT control_widget is a member
       QVBoxLayout * layout = new QVBoxLayout(); //IMPORTANT!!!! - Here it was QFormLayout
    
       layout->setAlignment(Qt::AlignTop); //IMPORTANT - Needed this after switching to QVBoxLayout
    
       layout->addWidget(new QComboBox("stuff")); //Some combo box
       control_widget->setLayout(layout);
    
       main_layout->addWidget(control_widget);
    }
    
    //Later on, we have a "Put a new widget in the control area" task
    void NewControlArea()
    {
       if(current_control)
          control_widget->removeWidget(current_control);  //current_control is a member variable
    
       current_control = new MyWidget();  //FROM ABOVE
       control_widget->addWidget(current_control);
    }
    

    If MyWidget uses a QFormLayout, things are not expanded unless I add spacers with size hints. However, if MyWidget uses a QVBoxLayout, any QWidgets inside it are expanded correctly.

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

Sidebar

Related Questions

I would like to only force the implementation of a C# getter on a
I would like to force EntityFramework saving dates with only seconds precision. How can
I would like to force a functions parameters to accept only specific definitions. For
I would like to know if it's possible to force the XXXXX would like
We would like to force encryption of the data going to and from our
I would like to force a \marginpar to appear on the wrong side of
I have an application I would like to force SSL on the login page
If I have an object that I would like to force to be accessed
I have a string property that I would like to be able to force
I recently found out about Cytoscape.js and would like to try out the force-directed

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.