I have an application, in which at one point of execution a dialog box is opened, waiting for the user to respond and according to his response the application acts.
This dialog box I need to be a QMainwindow
.
I know that if I do it with a QDialog
it fixes it, but I would like to know if there is a way to do it with QMainwindow
.
I have made a test scenario, WINDOW 2 is QMainWindow
in a Modal modality and the print order is executed even if it has not been closed and WINDOW 3 is QDialog
and the print is not executed until the window has not been closed.
import sys
from PyQt6 import QtCore, QtWidgets
class Ui_FirstWindow(object):
def setupUi(self, FirstWindow):
FirstWindow.resize(400, 300)
self.centralWidget = QtWidgets.QWidget(FirstWindow)
self.pushButton = QtWidgets.QPushButton(self.centralWidget)
self.pushButton.setGeometry(QtCore.QRect(110, 130, 191, 23))
self.pushButton.setText("Load Second Window")
self.pushButton2 = QtWidgets.QPushButton(self.centralWidget)
self.pushButton2.setGeometry(QtCore.QRect(110, 170, 191, 23))
self.pushButton2.setText("LoadThirdWindow")
FirstWindow.setCentralWidget(self.centralWidget)
def LoadSecondWindow(self):
SecondWindow = QtWidgets.QMainWindow()
ui = Ui_SecondWindow()
ui.setupUi(SecondWindow)
SecondWindow.show()
class Ui_SecondWindow(object):
def setupUi(self, SecondWindow):
SecondWindow.resize(400, 300)
self.centralWidget = QtWidgets.QWidget(SecondWindow)
self.pushButton = QtWidgets.QPushButton(self.centralWidget)
self.pushButton.setGeometry(QtCore.QRect(110, 130, 191, 23))
SecondWindow.setCentralWidget(self.centralWidget)
self.pushButton.setText('PushButton')
class Controller:
def __init__(self):
pass
def Show_FirstWindow(self):
self.FirstWindow = QtWidgets.QMainWindow()
self.ui = Ui_FirstWindow()
self.ui.setupUi(self.FirstWindow)
self.ui.pushButton.clicked.connect(self.Show_SecondWindow)
self.ui.pushButton2.clicked.connect(self.Show_ThirdWindow)
self.FirstWindow.show()
def Show_SecondWindow(self):
self.SecondWindow = QtWidgets.QMainWindow()
self.ui = Ui_SecondWindow()
self.ui.setupUi(self.SecondWindow)
self.SecondWindow.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal)
self.SecondWindow.show()
print("Don't Stop")
def Show_ThirdWindow(self):
self.ThirdWindow = QtWidgets.QDialog()
self.ThirdWindow.exec()
print('Yess Stop')
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
Controller = Controller()
Controller.Show_FirstWindow()
sys.exit(app.exec())