Switching from QDialog to another QDialog window
-
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)
-
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.
-
@LT-K101 https://doc.qt.io/qt-5/qwizard.html has already example code. What exactly is not clear?
-
@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. -
@jsulm Thanks for your assistance, can I show you my code if you don't mind?
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_())
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()
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()
-
@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?
-
@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