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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:04:32+00:00 2026-05-27T11:04:32+00:00

I have a horizontal QSplitter with two widgets. I want to replace the right

  • 0

I have a horizontal QSplitter with two widgets. I want to replace the right hand widget with a new one in a way that the proportions the user has set are maintained. Below is a simplified version of the code I currently have:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    splitter = new QSplitter(this);
    splitter->setOrientation(Qt::Horizontal);

    leftWidget = new QPushButton("left", splitter);
    rightWidget = new QPushButton("right", splitter);

    splitter->addWidget(leftWidget);
    splitter->addWidget(rightWidget);

    setCentralWidget(splitter);
}

void MainWindow::swapLayout()
{
    QList<int> sizes = splitter->sizes();

    rightWidget->deleteLater();
    splitter->update();

    rightWidget = new QPushButton("new right", splitter);

    splitter->addWidget(rightWidget);
    splitter->setSizes(sizes);
}

swapLayout() saves the sizes, removes the right widget, adds a new right hand widget and attempts to reset the sizes. However the left hand widget occupies 100% of the space. Without trying to restore the sizes the widgets both take up 50% of the space.

  • 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-27T11:04:32+00:00Added an answer on May 27, 2026 at 11:04 am

    I think the actual order of operations is:

    1. saving sizes of 2 widgets;
    2. adding 3rd widget.
    3. setting size for 3 widgets (and sizes.at(2) is 0 by default.
    4. Deleting 2nd widget.

    It caused by the fact that deleteLater() only schedules deleting, and actual deleting is processed after you exit swapLayout() method. Try delete rightWidget; instead of rightWidget->deleteLater(); if it possible. Or process events between deleting rightWidget and adding new one.

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

Sidebar

Related Questions

I want to have horizontal lists that can run as wide as possible but
I have two horizontal divisions and i want to insert a slider in between
I have an horizontal menu and I want to rotate 90° left or right
Do you know any controls inherited from the ItemsControl that have horizontal orientation of
I have a splitcontainer with horizontal orientation. I want a fixed height for panel2
i have a that contains a HORIZONTAL menu. the menu consists of an unordered
I have a ul list that I display as a horizontal menu. I'd like
I'm attempting a centered, two-column layout and I'd like to have horizontal rules in
I have a horizontal header and I'm setting it up to catch right clicks
I have a Horizontal Layout in which some vertical layouts are dispatched. I want

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.