What is the best way to "swap" one QGraphicsWidget
with another in an existing view? I have a tree view widget and a label widget, and I want them to occupy the same space at different times. Specifically, when there's an error, I want to show it in the label, and when there's no error, I want to show the tree.
I have tried programmatically hiding one and showing the other with hide()
and show()
, but the problem is that the hidden widget occupies space in my QGraphicsLinearLayout
even when it's hidden, leaving an empty gap. Alternatively, I suppose I could add and remove the widgets from the layout, but that seems heavy-handed since it implies a change in ownership of the widgets and I'd need to record their position in the layout so I could insert them back in the right place.
In Java Swing, I'd use a CardLayout
to achieve this, but I don't see an equivalent in Qt.
UPDATE: I discovered QStackedWidget
. However, I am working with a QGraphicsScene
and so my widgets don't inherit from QWidget
but rather QGraphicsWidget
, so I can't add them to a QStackedWidget
.