'PyQt5 make the full window app moveable/scrollable [duplicate]

How are you supposed to have a PyQt5 window to be scrollable (up/down and left/right). For instance, in the image it crops it and either I make the window bigger, either I cannot see it (obviusly if the window is bigger than the screen you'll never see everything).

enter image description here

In the code, I simply create a Window, and later I fill everything in a Dialog.

# Create gui
app = QtWidgets.QApplication(sys.argv)
dialog = QtWidgets.QDialog()
gui = network.MyGui(dialog)

The network.MyGui takes the dialog just created and adds to it some blocks.

class MyGui(QtWidgets.QDialog):
    def __init__(self, dialog, parent=None):
        super(MyGui, self).__init__(parent)
        self.dialog = dialog
        self.scrollArea = QtWidgets.QScrollArea(self) # Dont't work
        self.scrollArea.setWidgetResizable(True)

It is not limited by any number, meaning that if I want 200 blocks (bl#n), there will be 200 group boxes separed by some pixels each.



Solution 1:[1]

To add chilren to widget you need to create layout, then add children to layout, then set layout to parent.

from PyQt5 import QtGui, QtWidgets

class MyGui(QtWidgets.QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)
        layout = QtWidgets.QVBoxLayout()
        scrollArea = QtWidgets.QScrollArea(self)
        self._scrollArea = scrollArea

        label = QtWidgets.QLabel("use composite widget instead of label here")
        scrollArea.setWidget(label)

        layout.setContentsMargins(0,0,0,0)
        layout.addWidget(scrollArea)
        self.setLayout(layout)
        
if __name__ == "__main__":
    app = QtWidgets.QApplication([])

    gui = MyGui()
    gui.show()

    app.exec()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mugiseyebrows