qt - Python: How to unassign Layout from GroupBox in PyQt -


a groupbox:

mygroupbox = qtgui.qgroupbox() 

and 2 layouts:

layouta = qtgui.qvboxlayout() layoutb = qtgui.qvboxlayout() 

i assign layouta mygroupbox:

mygroupbox.setlayout(layouta) 

later there need re-assign layoutb mygroupbox:

mygroupbox.setlayout(layoutb) 

but getting warning...

qwidget::setlayout: attempting set qlayout "" on qwidget "", has layout 

is possible avoid warning? how remove layout mygroupbox before attempting assign another?

in order set new, top-level layout widget, must delete existing 1 , child items. deleting child items straightforward, deleting layout must done forcibly using sip module.

here's implementation:

import sip  def deletelayout(layout):     if layout not none:         while layout.count():             item = layout.takeat(0)             widget = item.widget()             if widget not none:                 widget.deletelater()             else:                 deletelayout(item.layout())         sip.delete(layout) 

if want keep existing layout , child items, give widget permanent top-level layout, , switch sub-layouts, this:

    self.widget = qtgui.qwidget(self)     layout = qtgui.qvboxlayout(self.widget)     layout.setcontentsmargins(0, 0, 0, 0)     self.vbox1 = qtgui.qvboxlayout()     self.vbox2 = qtgui.qvboxlayout()     layout.addlayout(vbox1)     ...      self.widget.layout().removeitem(self.vbox1)     self.widget.layout().addlayout(self.vbox2) 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -