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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:15:42+00:00 2026-06-08T01:15:42+00:00

I have a layout (containing QLabels and QSpacers) set on a button and I

  • 0

I have a layout (containing QLabels and QSpacers) set on a button and I want to replace this with a new one. To do this I have made the following code:

while(!layout.isEmpty())
{
    delete(layout.takeAt(0));
}

After this I set the new layout:

layout.addWidget(...)
layout.addSpacer(...)
...
button.setLayout(layout)

Unfortunately the new layout is set, but the old one can still be seen. How do I solve this?

  • 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-08T01:15:45+00:00Added an answer on June 8, 2026 at 1:15 am

    Based on your comments, you want to delete the items in the widget, not the layout. QLayout::takeAt returns a QLayoutItem*. Thus, you are looping through the widget’s layout and deleting the layout items, but not the widgets that were added to the layout items. As a test, you might try the following instead:

    while(!layout.isEmpty())
    {
        delete layout.itemAt(0)->widget();
        delete layout.takeAt(0);
    }
    

    However, this isn’t what I would consider a good long-term design. There may be a few special cases where this is the best method, but I would recommend looking into using a stacked widget or something similar to switch back and forth between the widgets presented, rather than destroy and recreate a whole array of widgets in a button. Alternately, consider two different buttons, and destroy and reinsert just the button rather than the contents of the button.

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

Sidebar

Related Questions

I have a Layout containing a fragment. I set width of Layout to let's
I have a layout like this in which I want to display a label
I have a layout with two children one after another, like this: |<view1><text1> |
I have a layout containing two textViews and one ImageView. the first text is
I have a layout that looks like this: It's a table with one cell
Okay, I made a XML Layout file containing a + and - button, and
I have a tab layout containing 3 tabs. I want to add 4th tab
I have a FileMaker Pro 11 layout containing a button with an action of
I have a panel with a form layout, containing several buttons. now I want
I have a fairly complex layout (containing RelativeLayouts, TextViews and ImageViews) that 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.