Important: Please read the Qt Code of Conduct -

How to add navigation to application

  • Hello, first off I am new to PyQt5, so I apologize if I make a mistake in my explanation.

    I am building a desktop application, and I am trying to figure out how to navigate to a new page once an event is triggered such as a click on a QPushButton. Right now, I have a login page, and I would like to display the user's dashboard if they use the correct credentials.

    The issue I am having is understanding how to do the actual updating to the screen. If possible, I would like to have two classes one for the login screen, and another for the dashboard and then just replace the login part with the dashboard when it's needed. I have tried to do something like this, but I end up with 2 individual windows rather than just updating the current window. I might be able to write some messy logic that would utilize the .close() and .show() methods, but I would imagine there is a cleaner way to do so.

    A Brief Version of My Code

    # This class is for displaying the simple login screen 
    class Login(QtWidgets.QMainWindow):
        def __init__(self):
            super(Login, self).__init__()
            login_path = ".//UI Files//login.ui"
            uic.loadUi(os.path.join(login_path, "login.ui"), self) 
            self.loginbutton = self.findChild(QtWidgets.QPushButton,"loginbutton")
            self.usernamefield = self.findChild(QtWidgets.QLineEdit, "usernamefield")
            self.passwordfield = self.findChild(QtWidgets.QLineEdit, "passwordfield")
            def sometypeoffunction(self):
             # This function would just verify the credentials 
    # This class would be for displaying the dashboard
    class MainUI(QtWidgets.QMainWindow):
        def __init__(self):
            super(MainUI, self).__init__()
            ui_path = os.path.dirname(os.path.abspath(__file__))
            uic.loadUi(os.path.join(ui_path, "mainui.ui"), self) 
            # Sidebar assignments 
            self.logo = self.findChild(QtWidgets.QLabel,"logo")
            self.newpatientbuttion = self.findChild(QtWidgets.QLabel,"newpatientbutton")   
            self.graphlist = QtWidgets.QListWidget(self)
            temp = ["One", "Two", "Three"]
            self.graphlist.setStyleSheet("background-color: rgb(209, 102, 24); border:none; color:white")
            self.graphlist.setFont(QtGui.QFont("Ariel", 14))
            #Topbar assignemts
            self.searchbar = self.findChild(QtWidgets.QLineEdit, "lineEdit")
            self.logoutbutton = self.findChild(QtWidgets.QLabel,"logoutbutton")
            self.confirmbutton = self.findChild(QtWidgets.QPushButton, "confirmbutton")
    def main():
        app = QtWidgets.QApplication(sys.argv)
        login = Login()
        # I would need some way to not show window until the login is verified 
        window = MainUI()
    if __name__ == "__main__":

    My WireFrame for Context

    I want to start off from a login page as so
    Wireframe login.PNG

    Then once the user logs in, the application should update as so,


    From within this dashboard, it would as update as so
    Wireframe Profile.PNG

    My Take
    I believe that my problem here is that both classes inherit from QMainWindow however, I am not exactly how to handle this situation. Should just the Login class inherit from this class? If so, then what should MainUI inherit from? I could be completely wrong, but I wanted to attempted this before asking for help. If someone could explain to me what I am doing wrong I would greatly appreciate it. I haven't been able to find many similar examples so, I am running out of solutions I can think of. Thank you.

  • Lifetime Qt Champion

    @Kyler The log-in window does not have to be a main window. Simply use a widget without parent - it will be shown as window. Or better use QDialog for that.

Log in to reply