Amphyby
Amphyby

Reputation: 83

re-setting layout for widget pyqt

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.

Upvotes: 0

Views: 890

Answers (1)

Amphyby
Amphyby

Reputation: 83

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)

Upvotes: 1

Related Questions