I do a desktop application on python3 + pyqt5, which consists of several components:

  • menu /
    • menu.py
    • menu.ui
  • main /
    • main.py
    • main.ui
  • app /
    • app.py
    • app.ui
  • default /

    • default.py
    • default.ui

    I need to implement switching between the mappings of different components in one window. Those. there is a main window divided horizontally into two parts by two widgets and you need to display the menu taken from menu / menu.py in the upper widget, and the contents of the widget from default / default.py in the lower widget when the program is turned on click on the button in the menu on app / app.py.

    I do not convert .ui files to .py and work with them like this:

    uic.loadUi("main/main.ui", self) self.hello_button.clicked.connect(self.print_text) 

    Please tell me what classes, methods of pyqt5 can insert and change the contents of widgets in the main window from the widgets of other program components.

    I tried various ways with hide () and show (), but this does not solve this problem. I studied the documentation, but a huge number of classes are confusing when looking for the right solution, plus this documentation for c ++ and, as a beginner, it’s quite difficult for me to understand it as quickly as, for example, python documentation.

    Thank you in advance for all the answers.

    1 answer 1

    You can see the class QStackedWidget . This class allows you to add several widgets to the stack, and then display exactly the one you need by changing the index .

    • Thanks a lot, it looks like exactly what you need. Even from the first time it turned out to show the contents of the imported widget. - Roman Arsenyev