You can use the QStackedWidget as a central widget and add a login screen and "login" to it.
Usage example:
from PyQt4 import QtCore, QtGui class MainWindow(QtGui.QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.central_widget = QtGui.QStackedWidget() self.setCentralWidget(self.central_widget) login_widget = LoginWidget(self) login_widget.button.clicked.connect(self.login) self.central_widget.addWidget(login_widget) def login(self): logged_in_widget = LoggedWidget(self) self.central_widget.addWidget(logged_in_widget) self.central_widget.setCurrentWidget(logged_in_widget) class LoginWidget(QtGui.QWidget): def __init__(self, parent=None): super(LoginWidget, self).__init__(parent) layout = QtGui.QHBoxLayout() self.button = QtGui.QPushButton('Login') layout.addWidget(self.button) self.setLayout(layout)
If you do not want to use this widget, I think you will have to call QMainWindow.setCentralWidget every time you change the center widget.
As for the login method, it depends. You could probably define a simple interface for your main window to add / remove / show certain central widgets and call it from the login LoginScreen method. Thus, the LoginScreen class LoginScreen not need to know about the implementation details, for example, if the central widget is actually a QStackedWidget , otherwise it is done in a different way.
source share