What is the best way to "swap" one QGraphicsWidget for another in its current form? I have a tree view widget and a shortcut widget, and I want them to occupy the same space at different times. In particular, when there is an error, I want to show it in the label, and when there is no error, I want to show the tree.
I tried programmatically hiding one and showing to others with hide() and show() , but the problem is that the hidden widget takes up space in my QGraphicsLinearLayout , even when it is hidden, leaving an empty space. Alternatively, I suppose I could add and remove widgets from the layout, but this seems difficult, as it involves changing the owner of the widget, and I will need to record their position in the layout so that I can insert them back in the right place.
In Java Swing, I would use CardLayout to achieve this, but I don't see the equivalent in Qt.
UPDATE: I discovered QStackedWidget . However, I work with QGraphicsScene , and therefore my widgets do not inherit from QWidget , but rather QGraphicsWidget , so I cannot add them to QStackedWidget .
c ++ qt layout widget
Rob h
source share