Ronikos Ronikos - 11 days ago 6
Python Question

PyQt5: TypeError: 'Wrong base class of toplevel widget'

I have created to .ui files using QtDesigner and I load them into two seperate windows as show below

class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__()

# Set up the user interface from Designer.
uic.loadUi("interface/UI/main.ui", self)

# Connect up the buttons
self.button_classes.clicked.connect(self.open_classes)

self.w = []

def open_classes(self):
self.w.append(PopupWindow(self))
self.w[-1].show()


class PopupWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__()

# Set up the user interface from Designer.
uic.loadUi("interface/UI/newclass.ui", self)


When I run the code in PyCharm in debug mode, the following error occurs, however this does not happen when the code is run normally

TypeError: ('Wrong base class of toplevel widget', (<class 'controllers.GUI.PopupWindow'>, 'QDialog'))

Answer

You have QDialog in message 'Wrong base class of toplevel widget', (<class 'controllers.GUI.NewClassWindow'>, 'QDialog')) so I think it expects you use QDialog to create second window but you use QMainWindow in class PopupWindowONE(QMainWindow):