Apr-03-2021, 01:27 PM
(This post was last modified: Apr-03-2021, 01:27 PM by deanhystad.)
They are not windows. They are classes that put stuff in a window. I see this done in tkinter a lot, probably because tkinter does strange things like initialize tkinter and create a window at the same time (Tk()). In Qt I am more used to seeing a window class which is a subclass of a Qt class. Such as class MyMainWindow(qtwidgets.QMainWindow).
If Ui_MainWindow was a window you would not be doing this:
If Ui_MainWindow was a window you would not be doing this:
class Ui_MainWindow(object): def SetupUi(self, MainWindow): super().__init__() MainWindow.setObjectName("MainWindow") MainWindow.setWindowTitle("Phreesia Hardware") MainWindow.setWindowModality(QtCore.Qt.NonModal) MainWindow.resize(900, 350) ... window = QtWidgets.QMainWindow() ui = Ui_MainWindow()2 ui.SutupUi(window)Instead your program would look more like this:
class Ui_MainWindow(QtWidgets.QMainWindow): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setWindowModality(QtCore.Qt.NonModal) self.resize(900, 350) ... ui = Ui_MainWindow() ui.setObjectName("MainWindow") ui.setWindowTitle("Phreesia Hardware")Differences are subtle, but making the UI_MainWindow class a window means it understands all the commands you can send to a window. I moved setObjectName and setWindowTitle out of the Ui_MainWindow class because now I can make two of these windows if I want and assign them different titles and give them different names.