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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:49:05+00:00 2026-05-21T23:49:05+00:00

I want a multi-color selection widget. The way I’m doing it is having a

  • 0

I want a multi-color selection widget. The way I’m doing it is having a “+” button, and an initially empty vbox. When + is pressed, it adds a QHBoxLayout to the vbox containing a “-” button and 3 spinboxes. When the “-” button is pressed I want that row to disappear and everything to go back to looking like it did before that row was added. The code I currently have is:

    vbox = self.ui.color_layout #from QtDesigner

    hbox = QtGui.QHBoxLayout()
    remove = QtGui.QPushButton("-", parent=self)

    remove.clicked.connect(lambda: vbox.removeItem(hbox))

    rspin = QtGui.QSpinBox(parent=self)
    gspin = QtGui.QSpinBox(parent=self)
    bspin = QtGui.QSpinBox(parent=self)

    hbox.addWidget(remove)
    hbox.addWidget(QtGui.QLabel("R:", parent=self))
    hbox.addWidget(rspin)
    hbox.addWidget(QtGui.QLabel("G:", parent=self))
    hbox.addWidget(gspin)
    hbox.addWidget(QtGui.QLabel("B:", parent=self))
    hbox.addWidget(bspin)

    vbox.addLayout(hbox)

Adding widgets works fine. However, removing them results in a really messed-up looking thing where the row isn’t actually removed, but the spacing is all messed up.

What am I doing wrong?

EDIT: The docs say, for removeWidget:

After this call, it is the caller’s responsibility to give the widget a reasonable geometry or to put the widget back into a layout.

How do I do that? (I come from a GTK background…)

EDIT 2: I even kept track of the rows and called the takeAt function to remove it, but it still gets messed up. What gives? It looks like the layout is removed but none of the widgets are…

EDIT 3: this also doesn’t work, just messes things up in a similar way:

    vbox = self.ui.color_layout

    hbox = QtGui.QHBoxLayout()

    row_widget = QtGui.QWidget(parent=self) #dummy widget to hold this stuff

    remove = QtGui.QPushButton("-", parent=self)

    def remove_func():
        vbox.removeWidget(row_widget)

    remove.clicked.connect(remove_func)

    rspin = QtGui.QSpinBox(parent=self)
    gspin = QtGui.QSpinBox(parent=self)
    bspin = QtGui.QSpinBox(parent=self)

    hbox.addWidget(remove)
    hbox.addWidget(QtGui.QLabel("R:", parent=self))
    hbox.addWidget(rspin)
    hbox.addWidget(QtGui.QLabel("G:", parent=self))
    hbox.addWidget(gspin)
    hbox.addWidget(QtGui.QLabel("B:", parent=self))
    hbox.addWidget(bspin)

    row_widget.setLayout(hbox)

    vbox.addWidget(row_widget)
  • 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-21T23:49:06+00:00Added an answer on May 21, 2026 at 11:49 pm

    Try removing from parent widget, not the layout.

    QLayout is not a parent, the parent for widgets being laid out is actually layout’s parent. For more info and a clearer explanation see documentation on Qt layouts.

    To remove widget, set its parent to None like this:

    widget = QWidget()    
    layout = QVBoxLayout()
    
    btn = QPushButton("To be removed")
    layout.addWidget(btn)
    widget.setLayout(layout)
    
    # later
    btn.setParent(None)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple processes monitoring an MSMQ queue. I want to do multi-step operations
I want to make a multi-language site, such that all or almost all pages
I have a multi-line string that I want to do an operation on each
I have a .NET (C#) multi-threaded application and I want to know if a
I have a multi-user ASP.NET app running against SQL Server and want to have
i have this multi dimentional array that i want to print into a table
Consider a window with loads of multi colored controls on it. I want to
Hi i want to add to my app multi-friend-selector. I found a method in
I have a multi-threaded application with (4) thread i want to know how much
If someone posts a multi-line post that contained text and links, I want to

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.