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. How do I switch from a QDialog in a QStackedWidget to a QMainWindow?

How do I switch from a QDialog in a QStackedWidget to a QMainWindow?

Scheduled Pinned Locked Moved Solved General and Desktop
qdialogqmainwindowscreen rotation
8 Posts 3 Posters 903 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.
  • J Offline
    J Offline
    Jonikles
    wrote on 22 May 2023, 18:32 last edited by Jonikles
    #1

    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!

    1 Reply Last reply
    0
    • S SGaist moved this topic from Qt in Education on 22 May 2023, 18:47
    • J Jonikles
      30 May 2023, 14:27

      @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.

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 30 May 2023, 14:32 last edited by jsulm
      #5

      @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.

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

      J 2 Replies Last reply 30 May 2023, 15:08
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 22 May 2023, 18:51 last edited by
        #2

        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.

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

        J 2 Replies Last reply 22 May 2023, 19:07
        1
        • S SGaist
          22 May 2023, 18:51

          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.

          J Offline
          J Offline
          Jonikles
          wrote on 22 May 2023, 19:07 last edited by
          #3

          @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 :)

          1 Reply Last reply
          0
          • S SGaist
            22 May 2023, 18:51

            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.

            J Offline
            J Offline
            Jonikles
            wrote on 30 May 2023, 14:27 last edited by
            #4

            @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.

            J 1 Reply Last reply 30 May 2023, 14:32
            0
            • J Jonikles
              30 May 2023, 14:27

              @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.

              J Online
              J Online
              jsulm
              Lifetime Qt Champion
              wrote on 30 May 2023, 14:32 last edited by jsulm
              #5

              @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.

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

              J 2 Replies Last reply 30 May 2023, 15:08
              0
              • J jsulm
                30 May 2023, 14:32

                @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.

                J Offline
                J Offline
                Jonikles
                wrote on 30 May 2023, 15:08 last edited by
                #6

                @jsulm Heyyy I got it working! thank you to both of you!

                1 Reply Last reply
                0
                • J jsulm
                  30 May 2023, 14:32

                  @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.

                  J Offline
                  J Offline
                  Jonikles
                  wrote on 30 May 2023, 15:24 last edited by Jonikles
                  #7

                  @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.

                  S 1 Reply Last reply 30 May 2023, 19:14
                  0
                  • J Jonikles
                    30 May 2023, 15:24

                    @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.

                    S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 30 May 2023, 19:14 last edited by
                    #8

                    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.

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

                    1 Reply Last reply
                    1
                    • J Jonikles has marked this topic as solved on 31 May 2023, 21:30

                    • Login

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