Issue with QDialog-based Interface: Scene Transition Problem in Qt Creator.
-
I've encountered an issue with scene transitions in my interface, based on the QDialog class. After loading the 'menu.ui' scene and clicking the 'login' button on the 'registration.ui' scene, the button intended to load the next scene ('createTask.ui') after 'menu.ui' doesn't work. I want the registration window to appear first, then transition to the menu, and upon button press, open the new 'createTask.ui' window, but it's not happening. I'm working in Qt Creator.
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox import sqlite3 from PyQt5.QtCore import Qt from PyQt5.uic import loadUi import database_operations class RegistrationWindow(QDialog): def __init__(self, parent=None): super().__init__(parent) loadUi("registration.ui", self) self.pushButtonRegister.clicked.connect(self.register_user) self.pushButtonLogin.clicked.connect(self.login_user) self.setWindowFlags(self.windowFlags() | Qt.WindowMinimizeButtonHint) self.menu_window = loadUi("menu.ui") def register_user(self): username = self.lineEditUsername.text() password = self.lineEditPassword.text() if not username or not password: QMessageBox.warning(self, "Error", "Please fill in the fields.") return conn = sqlite3.connect(database_operations.db_path) cur = conn.cursor() cur.execute("SELECT * FROM users WHERE username=?", (username,)) existing_user = cur.fetchone() if existing_user: QMessageBox.warning(self, "Error", "User with this name already exists") else: cur.execute("INSERT INTO users (username, password) VALUES (?, ?)", (username, password)) conn.commit() QMessageBox.information(self, "Success", "Registration successful") conn.close() def login_user(self): username = self.lineEditUsername.text() password = self.lineEditPassword.text() if not username or not password: QMessageBox.warning(self, "Error", "Please fill in the fields.") return conn = sqlite3.connect(database_operations.db_path) cur = conn.cursor() cur.execute("SELECT * FROM users WHERE username=? AND password=?", (username, password)) existing_user = cur.fetchone() if existing_user: self.hide() self.menu_window.show() else: QMessageBox.warning(self, "Error", "Incorrect username or password") conn.close() def main(): app = QApplication(sys.argv) window = RegistrationWindow() window.show() sys.exit(app.exec_()) if __name__ == "__main__": main()
from PyQt5.QtWidgets import QApplication, QDialog from PyQt5.uic import loadUi class MenuWindow(QDialog): def __init__(self): super().__init__() loadUi("menu.ui", self) self.createTaskButton.clicked.connect(self.load_create_task_dialog) def load_create_task_dialog(self): create_task_dialog = CreateTaskDialog() create_task_dialog.exec_() class CreateTaskDialog(QDialog): def __init__(self): super().__init__() loadUi("createTask.ui", self) def main(): app = QApplication(sys.argv) menu_window = MenuWindow() menu_window.show() sys.exit(app.exec_()) if __name__ == "__main__": main()
-
I don't understand your code. Why do you have two main() functions where you create QApplication instances?
There should be only one main() function and one QApplication instance.
The logic to continue with next ui should not be inside RegistrationWindow. RegistrationWindow should only tell the caller the status and depending on this status the caller decides what to show next. "Caller" can be the main() function or Main Window. -
@jsulm that allows each file to be executed independently (I agree, it can be confusing).
@guccimane192 you're hiding your current widget which is the current top level widget and this triggers the ending of the application.
-