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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:29:57+00:00 2026-05-14T14:29:57+00:00

I am using a QVBoxLayout to arrange a vertical stack of widgets. The QVBoxLayout

  • 0

I am using a QVBoxLayout to arrange a vertical stack of widgets. The QVBoxLayout is contained within a QScrollArea. I want some of the widgets to be initially hidden and only show up when a check box is checked. Here is an example of the code I’m using.

MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
{
    QVBoxLayout *layout = new QVBoxLayout(this);

    QLabel *labelLogTypes = new QLabel(tr("Log Types"));

    m_checkBoxCsv = new QCheckBox(tr("&Delimited File (CSV)"));
    m_labelDelimiter = new QLabel(tr("Delimiter:"));
    m_lineEditDelimiter = new QLineEdit(",");
    checkBoxCsv_Toggled(m_checkBoxCsv->isChecked());
    connect(m_checkBoxCsv, SIGNAL(toggled(bool)), SLOT(checkBoxCsv_Toggled(bool)));

    QHBoxLayout *layoutDelimitedChar = new QHBoxLayout();
    layoutDelimitedChar->addWidget(m_labelDelimiter);
    layoutDelimitedChar->addWidget(m_lineEditDelimiter);


    m_checkBoxXml = new QCheckBox(tr("&XML File"));
    m_checkBoxText = new QCheckBox(tr("Plain &Text File"));


    // Now that everything is constructed, put it all together
    // in the main layout.
    layout->addWidget(labelLogTypes);

    layout->addWidget(m_checkBoxCsv);
    layout->addLayout(layoutDelimitedChar);

    layout->addWidget(m_checkBoxXml);
    layout->addWidget(m_checkBoxText);

    layout->addStretch();
}


MyWidget::checkBoxCsv_Toggled(bool checked)
{
    m_labelDelimiter->setVisible(checked);
    m_lineEditDelimiter->setVisible(checked);
}

I want m_labelDelimiter and m_lineEditDelimiter both to be initially invisible and I want their visibility to toggle with the state of m_checkBoxCsv. When they become visible, I would like the layout to expand vertically to accommodate them.

This code achieves the functionality I desire, but it doesn’t seem to reserve space for the two initially hidden widgets. When I check the checkbox, they become visible, but everything is kind of scrunched to accommodate them.

If I leave them initially visible, everything is laid out just the way I would like it. Is there any way to make the QVBoxLayout reserve space for these widgets even if they’re initially invisible?

If I don’t put this widget into a QScrollArea, then this code works exactly as I want it to. What is the deal with the QScrollArea?

  • 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-14T14:29:57+00:00Added an answer on May 14, 2026 at 2:29 pm

    I apologize for not being totally clear in my original question. It turns out that the problem seems to have been related to this widget having been contained within a QScrollArea. When I called scrollArea->setWidgetResizable(true), things started to work perfectly.

    Thanks for your suggestions, serge and Caleb.

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

Sidebar

Related Questions

I'm using the Qt Designer. I want to create a QVBoxLayout which will automatically
Using a populated Table Type as the source for a TSQL-Merge. I want to
I have this little test-case which is supposed to show two widgets, with one
Using restlet, I want to make a post to android's c2dm service. I have
I want to divide my window in the following manner Build a vertical layout
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
(Using Qt 4.6.3, x64, linux) I'm testing how to properly insert widgets into a
Using HTML 5, I want to play multiple sounds simultaneously. how can I do
Using the Exiv2 library to write some exif tags to an image i'm running
Using JQuery, how do I select all elements with class x within an element

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.