0
votes

Welcome!

I am trying to create my own gui app using PyQT(5 i guess). Well, mainwindow consists of menubar, statusbar and central widget. Central widget is QTabWidget. In each tab there is it's own workplace widget.

the program itself allows to create a pipline of OpenFOAM stages, set the options for each process and launch it. It's all is to be made in one widget that is the only widget in a tab.

The problem i encountered is connected to QLayout. I am using QHBoxLayouts and QVBoxLayouts combination on each step of launching the task. When I make initial self.setLayout(somelayout1) it works fine. But as i make next steps in different methods of this widget's class self.setLayout(somelayout2), self.setLayout(somelayout3) and so on, the new layout becomes being drawn on the top of all the previous layouts. More than this: all the layers' parts of previous layouts that not covered by new one are remain active!

haven't found any working method for disabling old layout of the widget, or better: removing it. Already tried even creating a layout container of 1 element and influencing it with self.layout().removeItem(0) and self.layout().setLayout(newlayout) (or .inserLayout(newlayout), but there is no difference.

Is there any working method to change the layout of the widget without appearing the old one on a backside?

thanks for any help.

p.s.: self.setStyleSheet("QWidget { background-color: rgb(255, 255, 255) }") neither QObjectCleanupHandler().add(self.layout()) both make no effect.

1
@ekhumoro i'll try it, and leave a reply, thanks!Amphyby
PS: to delete a layout and all its widgets, see this answer.ekhumoro
@ekhumoro Hm, I thank you. That seems to be working. I mean clearing of layout. The weird fact is the privious one still on the down-layer of my widget. and the new one is on the top. More than this - it's still active... I'm sure that your method clears layout - inserted several print(self.layout().count()) there. But still can't get rid of old layouts on the gui itself. mystery.Amphyby
Try using stack widget. Make all of your widgets and then just set the current index of the stack widget for every step that needs to change the layout.justengel

1 Answers

1
votes

The way to ensure deleting widget from old layout is using sip.delete(somewidget). This will delete C++ object itself(because sometimes it keeps existing on it's own)