How to replace a Widget with another using Qt ?
- by Natim
Hi,
I have an QHBoxLayout with a QTreeWidget on the left, a separator on the middle and a widget on the right.
When I click on the QTreeWidget, I want to change the widget on the right to modify the QTreeWidgetItem
I tried to do this with this code :
def new_rendez_vous(self):
self.ui.horizontalLayout_4.removeWidget(self.ui.editionFormWidget)
del self.ui.editionFormWidget
self.ui.editionFormWidget = RendezVousManagerDialog(self.parent)
self.ui.editionFormWidget.show()
self.ui.horizontalLayout_4.addWidget(self.ui.editionFormWidget)
self.connect(self.ui.editionFormWidget, QtCore.SIGNAL('saved'), self.scheduleTreeWidget.updateData)
def edit(self, category, rendez_vous):
self.ui.horizontalLayout_4.removeWidget(self.ui.editionFormWidget)
del self.ui.editionFormWidget
self.ui.editionFormWidget = RendezVousManagerDialog(self.parent, category, rendez_vous)
self.ui.editionFormWidget.show()
self.ui.horizontalLayout_4.addWidget(self.ui.editionFormWidget)
self.connect(self.ui.editionFormWidget, QtCore.SIGNAL('saved'), self.scheduleTreeWidget.updateData)
def edit_category(self, category):
self.ui.horizontalLayout_4.removeWidget(self.ui.editionFormWidget)
del self.ui.editionFormWidget
self.ui.editionFormWidget = CategoryManagerDialog(self.parent, category)
self.ui.editionFormWidget.show()
self.ui.horizontalLayout_4.addWidget(self.ui.editionFormWidget)
self.connect(self.ui.editionFormWidget, QtCore.SIGNAL('saved'), self.scheduleTreeWidget.updateData)
But it doesn't work and all the widgets are stacked up on each other :
.
Do you know how I can remove the old widget and next display the new one ?