Search code examples
qtpyqtparentchildwindow

How to put a child window inside a main window(PyQt)


I looked here in stackoverflow and google for some days for something like my case, but all the examples I found did not work.

What I want is to have my parent window with the menu, and then call other child windows from that menu and execute/show them inside the parent window.

I tried put a widget in the parent window and call the child window inside of it, use MDIArea, but nothing worked.

Obs.: My screen files are generated from Qt designer, and I'm making separated classes to manipulate the widgets, pushbuttons, etc to keep everything more organized.

I created MdiArea in my main window using QtDesigner and them in a class triggered by clicking a menu I call the subwindow (a widget created with QtDesigner too) inside the MdiArea.

from resources.SubWindowQtDes import Ui_SubWindow
from resources.MainWindowQTDes import Ui_MainWindow
class cadastraAluno(Ui_SubWindow,Ui_MainWindow):
    def __init__(self, parent=None):
        super(cadastraAluno, self).__init__(parent = None)
        dialog = Ui_SubWindow()
        window = Ui_MainWindow()
        mdi = window.mdiArea
        mdi.addSubWindow(dialog, flags = 0)
        dialog.show()

Solution

  • I found a way. I used self.show() instead of dialog.show() and self.mdiAreainstead of window.mdiArea.

    Now I close the window and show it again with the widgets I want. I want to find a way to just "refresh" the window. But this is subject for another topic.
    Thanks a lot guys.