Search code examples
pythonpython-3.xqtpyside6

How to add the Layout to QStackedLayout?


I'm trying to add some layouts to QStackedLayout.

self.rightLayout = QtWidgets.QStackedLayout()
self.rightLayout.addItem(QtWidgets.QVBoxLayout())

However, it throws the warning:

QStackedLayout::addItem: Only widgets can be added

It is possible to use QStackedLayout to manipulate another layouts? Or may be some other way to switch layouts should be used?


Solution

  • One possible solution is to use a QWidget as a container:

    container = QtWidgets.QWidget()
    lay = QtWidgets.QVBoxLayout(container)
    
    self.rightLayout = QtWidgets.QStackedLayout()
    self.rightLayout.addWidget(container)