0

I hope I have a simple question here. I have created a very large GUI with QT Designer and a subwindow for the MDI area. I have used pyuic5 to convert it from a .ui file to a .py file. I have written a function to open that subwindow when a button is pressed. The first time I push the button it works fine. The problem I'm having is the second time the button is pushed it just displays a blank subwindow within the MDI area. How do I get it to display correctly every time the button is pressed. I will attach the code for how I launch the subwindow below. Any advice would be very appreciated. Thank you for your time and your help

Code that is called when button is clicked

def windowaction(self):

    sub = QtWidgets.QMdiSubWindow()
    sub.setWidget(self.Load_Input)
    sub.setObjectName("Load_Input_window")
    sub.setWindowTitle("Load Input")
    self.mdiArea.addSubWindow(sub)
    sub.show()

First time clicking the button First Time Clicking the button

Second time clicking the button Second Time Clicking the button

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
laxer
  • 720
  • 11
  • 41

1 Answers1

0

The problem arises from adding the same widget object to different QMdiSubWindow, you must create a new object and add it to the new QMdiSubWindow.

def windowaction(self):
    sub = QtWidgets.QMdiSubWindow()
    Load_Input = LoadInput()
    sub.setWidget(Load_Input)
    sub.setObjectName("Load_Input_window")
    sub.setWindowTitle("Load Input")
    self.mdiArea.addSubWindow(sub)
    sub.show()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thank you for your response. When I try that code I'm getting and error that says "`TypeError: 'QWidget' object is not callable"`. I noticed that the only difference is you have `Load_Input = LoadInput()` where I have the equivalent of `Load_Input = LoadInput`. What difference does the `()` make. Also since I am creating a new object would it be good to remove the old one before making a new one? In the end, I would like only one of the "Load input" windows to be open at once. – laxer May 05 '17 at 14:57
  • In your code you should have done something similar to self.Load_Input = , You could show me that line of code or share your project via github, dropbox or similar. – eyllanesc May 05 '17 at 14:59
  • I just made a github repository that can be found here. Also, the function is in the `Main.py` file. I'm trying to keep it all separated https://github.com/simplesports/WorkHelper – laxer May 05 '17 at 15:16
  • You could share the ui file. – eyllanesc May 05 '17 at 15:28
  • You must separate the design of each window, create a new form, in the following [link](https://github.com/eyllanesc/stackoverflow/tree/master/WorkHelper) I have separated, When you create an object of class `myclass` you must do something similar to obj = `myclass()`, instead you were using an object that was already created. – eyllanesc May 05 '17 at 15:50
  • That is fantastic!! Thank you so much! You have really taught me a lot and I am very thankful! – laxer May 05 '17 at 16:29