Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Switching from QDialog to another QDialog window
QtWS25 Last Chance

Switching from QDialog to another QDialog window

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 801 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LT-K101
    wrote on last edited by LT-K101
    #1

    I have a QMainWindow and Two QDialog windows, moving to the second QDialog window seem not working with a help of a next button. I think I might be doing something wrong here. Please I need assistance, below is my code. Thanks.

    QMainWindow Code

    from PyQt5 import QtCore, QtGui, QtWidgets
    from NewEmployee import AddEmployee
    
    
    class EmployeeWindow(QtWidgets.QMainWindow):
    
        def __init__(self, mainMenu):
            super(EmployeeWindow, self).__init__()
            self.mainMenu = mainMenu
    
            self.ui = Ui_MainWindow()
            self.ui.setupUi(self)
    
            self.ui.Back_Button.clicked.connect(self.Back_To_MainMenu)
            self.ui.Add_Employee_Button_2.clicked.connect(self.Add_New_Employee)
    
    
        def Back_To_MainMenu(self):
            self.hide()
    
            self.mainMenu.show()
    
    
        def Add_New_Employee(self):
            self.addEmployee = AddEmployee()
            first_result = self.addEmployee.exec()
    

    First QDialog Window Code

    from PyQt5 import QtCore, QtGui, QtWidgets
    from OtherEmployee_info import OtherEmployee
    
    
    class AddEmployee(QtWidgets.QDialog):
    
        def __init__(self):
            super(AddEmployee, self).__init__()
            self.ui = Ui_Dialog()
            self.ui.setupUi(self)
    
    
    class SecondEmployee(QtWidgets.QDialog):
    
        def __init__(self):
            super(SecondEmployee, self).__init__()
    
            self.ui = Ui_Dialog()
            self.ui.setupUi(self)
    
    
            self.ui.New_Employee_Next_Button.clicked.connect(Open_Second_Employee_Window)
    
    
        def Open_Second_Employee_Window(self):
            self.secondEmployee = SecondEmployee()
            second_result = self.secondEmployee.exec()
    

    Second QDialog Window Code

    from PyQt5 import QtCore, QtGui, QtWidgets
    
    class OtherEmployee(QtWidgets.QDialog):
    
        def __init__(self):
            super(OtherEmployee, self).__init__()
            self.ui = Ui_Dialog()
            self.ui.setupUi(self)
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You are creating event loops within event loops with your code.

      If you want to implement some sort of wizard, then you should consider using QWizard, otherwise, you should rather consider the use of QStackedWidget to switch from one widget to another within your dialog.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        You are creating event loops within event loops with your code.

        If you want to implement some sort of wizard, then you should consider using QWizard, otherwise, you should rather consider the use of QStackedWidget to switch from one widget to another within your dialog.

        L Offline
        L Offline
        LT-K101
        wrote on last edited by LT-K101
        #3

        @SGaist Thanks for your responds. I'm new to python and I'm kind of confused right now with Qwizard and QstackedWidget , could you please assist with some code so i can understand you properly please?

        jsulmJ 1 Reply Last reply
        0
        • L LT-K101

          @SGaist Thanks for your responds. I'm new to python and I'm kind of confused right now with Qwizard and QstackedWidget , could you please assist with some code so i can understand you properly please?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @LT-K101 https://doc.qt.io/qt-5/qwizard.html has already example code. What exactly is not clear?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          L 1 Reply Last reply
          0
          • jsulmJ jsulm

            @LT-K101 https://doc.qt.io/qt-5/qwizard.html has already example code. What exactly is not clear?

            L Offline
            L Offline
            LT-K101
            wrote on last edited by
            #5

            @jsulm I have a main.py file and QMainWindow.py file as the second page. Now I want to create two more pages using Qwizard within the QMainWindow. I used Qt designer in designing all my pages and converted them to .py files.

            jsulmJ 1 Reply Last reply
            0
            • L LT-K101

              @jsulm I have a main.py file and QMainWindow.py file as the second page. Now I want to create two more pages using Qwizard within the QMainWindow. I used Qt designer in designing all my pages and converted them to .py files.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @LT-K101 Still not sure what the problem is.
              Here is some Python example code: https://doc.qt.io/archives/qtforpython-5.12/PySide2/QtWidgets/QWizard.html
              You create a QWizard instance, add pages to it and show it.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              L 1 Reply Last reply
              0
              • jsulmJ jsulm

                @LT-K101 Still not sure what the problem is.
                Here is some Python example code: https://doc.qt.io/archives/qtforpython-5.12/PySide2/QtWidgets/QWizard.html
                You create a QWizard instance, add pages to it and show it.

                L Offline
                L Offline
                LT-K101
                wrote on last edited by LT-K101
                #7

                @jsulm Thanks for your assistance, can I show you my code if you don't mind?

                Main.py

                from PyQt5 import QtWidgets, QtCore
                from mainmenu import MainWindow
                
                if name == "main": import sys
                
                app = QtWidgets.QApplication(sys.argv)
                
                mainwindow = MainWindow()
                mainwindow.show()
                
                sys.exit(app.exec_())
                
                

                mainMenu.py

                from PyQt5 import QtCore, QtGui, QtWidgets
                from ManageEmployee import EmployeeWindow
                
                
                class MainWindow(QtWidgets.QMainWindow):
                
                    def __init__(self):
                        super(MainWindow, self).__init__()
                
                       self.ui = Ui_MainWindow()
                       self.ui.setupUi(self)
                
                       self.ui.Reg_Emp_Button.clicked.connect(self.manage_reg_Employees)
                    
                
                   def manage_reg_Employees(self):
                       self.hide()
                       self.employeeWindow = EmployeeWindow(self)
                       self.employeeWindow.show()
                
                

                ManageEmployee.py

                class EmployeeWindow(QtWidgets.QMainWindow):
                
                     def __init__(self, mainMenu):
                         super(EmployeeWindow, self).__init__()
                         self.mainMenu = mainMenu
                
                         self.ui = Ui_MainWindow()
                         self.ui.setupUi(self)
                
                         self.ui.Back_Button.clicked.connect(self.Back_To_MainMenu)
                         
                     def Back_To_MainMenu(self):
                         self.hide()
                
                         self.mainMenu.show()
                
                jsulmJ 1 Reply Last reply
                0
                • L LT-K101

                  @jsulm Thanks for your assistance, can I show you my code if you don't mind?

                  Main.py

                  from PyQt5 import QtWidgets, QtCore
                  from mainmenu import MainWindow
                  
                  if name == "main": import sys
                  
                  app = QtWidgets.QApplication(sys.argv)
                  
                  mainwindow = MainWindow()
                  mainwindow.show()
                  
                  sys.exit(app.exec_())
                  
                  

                  mainMenu.py

                  from PyQt5 import QtCore, QtGui, QtWidgets
                  from ManageEmployee import EmployeeWindow
                  
                  
                  class MainWindow(QtWidgets.QMainWindow):
                  
                      def __init__(self):
                          super(MainWindow, self).__init__()
                  
                         self.ui = Ui_MainWindow()
                         self.ui.setupUi(self)
                  
                         self.ui.Reg_Emp_Button.clicked.connect(self.manage_reg_Employees)
                      
                  
                     def manage_reg_Employees(self):
                         self.hide()
                         self.employeeWindow = EmployeeWindow(self)
                         self.employeeWindow.show()
                  
                  

                  ManageEmployee.py

                  class EmployeeWindow(QtWidgets.QMainWindow):
                  
                       def __init__(self, mainMenu):
                           super(EmployeeWindow, self).__init__()
                           self.mainMenu = mainMenu
                  
                           self.ui = Ui_MainWindow()
                           self.ui.setupUi(self)
                  
                           self.ui.Back_Button.clicked.connect(self.Back_To_MainMenu)
                           
                       def Back_To_MainMenu(self):
                           self.hide()
                  
                           self.mainMenu.show()
                  
                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @LT-K101 said in Switching from QDialog to another QDialog window:

                  can I show you my code if you don't mind?

                  Sure. But what exactly is the problem?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  L 2 Replies Last reply
                  1
                  • jsulmJ jsulm

                    @LT-K101 said in Switching from QDialog to another QDialog window:

                    can I show you my code if you don't mind?

                    Sure. But what exactly is the problem?

                    L Offline
                    L Offline
                    LT-K101
                    wrote on last edited by
                    #9

                    @jsulm From the code I have posted above, what I want to do is click a PushButton in the last QMainWindow(ManageEmployee.py) and a first QDialog page will show. Again when I click on a PushButton from the first QDialog it should show a second QDialog window. I do not know what code to put in the ManageEmployee.py script

                    1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @LT-K101 said in Switching from QDialog to another QDialog window:

                      can I show you my code if you don't mind?

                      Sure. But what exactly is the problem?

                      L Offline
                      L Offline
                      LT-K101
                      wrote on last edited by
                      #10

                      @jsulm I got a solution on youtube ,thanks a lot.

                      mrjjM 1 Reply Last reply
                      0
                      • L LT-K101

                        @jsulm I got a solution on youtube ,thanks a lot.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @LT-K101
                        Hi
                        Super. Could you then mark this a solved using the topic button in first post and
                        maybe also post the link to SO for the solution ?

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved