How do I switch from a QDialog in a QStackedWidget to a QMainWindow?
-
I'm trying to have a SignUp/Login QDialog go to a QMainWindow with my actual project for school, which is a music player. I cannot - for the life of me - figure out any way to have a QDialog that switches between a signup dialog screen to a login dialog screen (using a QStackedWidget) hide its screen to open up a QMainWindow. This is all also connected through a server - client but that's unimportant right now as I can't get through the first step of connecting between the two.
I have been able to switch between the 2 QDialog as I mentioned, and I'm able to switch between a single QDialog to a QMainWindow, by running an exec() in the middle of the code.
How can I combine the two? just to sum up: I want my user to open up their file and be introduced to a login screen in which they are able to go to a sign up screen and back and forth between the two. Once they decided whether they wanna create a user or login into an existing one and they press the appropriate button, they get sent to the main window.
Any suggestion that recommends switching qdialog to a qmainwindow are not as good but still very much appreciated
thanks everyone! -
-
@Jonikles said in How do I switch from a QDialog in a QStackedWidget to a QMainWindow?:
As for showing the QMainWindow, how can I show it from QDialog?
You do not start it from QDialog.
You show the dialog and then depending on the user selection you create the QMainWindow and show it or exit the application. All this is done inside main() function."Now how do I make it so that 2 QDialogs are child to the widget of the new main QDialog?" - not sure what exactly you mean by this. What @SGaist suggested is simply that you have one dialog with a stacked widget with two pages in it: one for signup and one for login.
-
Hi and welcome to devnet,
Use one single dialog that will contain the QStackedWidget with your signup and login widgets in it.
As for the move to the QMainWindow, don't overthink it. When you start your application, have a loop that will re-show your dialog until either the login is successful, the registration is successful or the user cancels. Based on the outcome of the dialog, exit the application or then show the QMainWindow.
-
@SGaist First of all, thank you! couldn't find anything on the internet for this haha.
that sounds like a good idea, I'll let you know how it goes. Please don't close the discussion until I'm completely finished with it in case I come across any issues along the implementation :)
-
@SGaist Hi again! So a little late but I started to work on it, and I think I'll need a little bit more hand-holding so sorry in advance.
I have in one file the 2 QDialog and their properties, and 2 files with their UI. Originally, I put the stackedwidget as the operator of the 2 QDialogs. Now how do I make it so that 2 QDialogs are child to the widget of the new main QDialog? Do I need to seperate the 2 in a different file and then connect? I feel like I'm overcomplicating it but I have no idea how else to do this.
As for showing the QMainWindow, how can I show it from QDialog? they are in 2 seperate files and I assume that importing it and then exec()'ing isn't the most optimal solution.
-
@Jonikles said in How do I switch from a QDialog in a QStackedWidget to a QMainWindow?:
As for showing the QMainWindow, how can I show it from QDialog?
You do not start it from QDialog.
You show the dialog and then depending on the user selection you create the QMainWindow and show it or exit the application. All this is done inside main() function."Now how do I make it so that 2 QDialogs are child to the widget of the new main QDialog?" - not sure what exactly you mean by this. What @SGaist suggested is simply that you have one dialog with a stacked widget with two pages in it: one for signup and one for login.
-
@jsulm Just one last thing, how do I now create the loop that SGaist was suggesting? How do I continuously check if the user has clicked a button from the main function in QDialog? And also a side note question, how I can detect if the user closed a window? not necessarily a QDialog but just as a general question.
-
If you use exec to show your dialog, you know it has ended when the method returns.
As for your other question, depending on what you want to do, you can use the close method to emit a custom signal for example but you don't give enough context to answer properly.
-