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. Implementing multiple Screens

Implementing multiple Screens

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 2 Posters 3.1k 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.
  • KiraK Offline
    KiraK Offline
    Kira
    wrote on last edited by
    #1

    Hello, everyone, I want to implement multiple screen functionality.
    For example, I have a screen 1 with a set of widgets similarly, screen 2 and 3, and so on. I have created a project which has QMainWindow widget with how can I replace the contents of my screen with the existing elements on the QMainWindow.
    Is there a specific approach for the same? Or what is the best way to implement the above functionality.

    jsulmJ 1 Reply Last reply
    0
    • KiraK Kira

      Hello, everyone, I want to implement multiple screen functionality.
      For example, I have a screen 1 with a set of widgets similarly, screen 2 and 3, and so on. I have created a project which has QMainWindow widget with how can I replace the contents of my screen with the existing elements on the QMainWindow.
      Is there a specific approach for the same? Or what is the best way to implement the above functionality.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Kira Sounds like https://doc.qt.io/qt-5/qstackedwidget.html is what you need

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

      KiraK 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Kira Sounds like https://doc.qt.io/qt-5/qstackedwidget.html is what you need

        KiraK Offline
        KiraK Offline
        Kira
        wrote on last edited by Kira
        #3

        @jsulm : Thanks for reply without stack widget.
        Can i replace the central widget with new widgets every now and then ?

        jsulmJ 1 Reply Last reply
        0
        • KiraK Kira

          @jsulm : Thanks for reply without stack widget.
          Can i replace the central widget with new widgets every now and then ?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Kira said in Implementing multiple Screens:

          Can i replace the central widget with new widgets every now and then ?

          You can, or you use the central widget as parent for the other widgets you want to put as "screens". So, as parent for your "screens".

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

          KiraK 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Kira said in Implementing multiple Screens:

            Can i replace the central widget with new widgets every now and then ?

            You can, or you use the central widget as parent for the other widgets you want to put as "screens". So, as parent for your "screens".

            KiraK Offline
            KiraK Offline
            Kira
            wrote on last edited by
            #5

            @jsulm :
            Thanks for the reply.
            Just for clarification, please verify the steps.
            Create multiple form file using inheriting Qwidget.
            Set the central widget to one of the widget form files.
            If the above approach is correct can you please provide an example
            because I am getting a lot of errors.

            jsulmJ 1 Reply Last reply
            0
            • KiraK Kira

              @jsulm :
              Thanks for the reply.
              Just for clarification, please verify the steps.
              Create multiple form file using inheriting Qwidget.
              Set the central widget to one of the widget form files.
              If the above approach is correct can you please provide an example
              because I am getting a lot of errors.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Kira said in Implementing multiple Screens:

              because I am getting a lot of errors.

              Please post the errors

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

              KiraK 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Kira said in Implementing multiple Screens:

                because I am getting a lot of errors.

                Please post the errors

                KiraK Offline
                KiraK Offline
                Kira
                wrote on last edited by
                #7

                @jsulm : Sorry for the delay in reply.
                I have created a git repo of the example, please have a look on the below link: https://github.com/HackersSpirit/SwitchingWidget
                I am facing the following issue:
                When I set the central layout to widget1, it works
                Setting the centralLayout to widget2 also works
                Resetting the centralLayout to widget1 causes the application to crash.

                jsulmJ 1 Reply Last reply
                0
                • KiraK Kira

                  @jsulm : Sorry for the delay in reply.
                  I have created a git repo of the example, please have a look on the below link: https://github.com/HackersSpirit/SwitchingWidget
                  I am facing the following issue:
                  When I set the central layout to widget1, it works
                  Setting the centralLayout to widget2 also works
                  Resetting the centralLayout to widget1 causes the application to crash.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Kira See https://doc.qt.io/qt-5/qmainwindow.html#setCentralWidget
                  "Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time."

                  I think if you set second widget as central widget the first one is automatically deleted as main window has the ownership. And if you then again try to set the first one it do4es not exist anymore and the pointer is invalid, hence the crash.
                  You can change your code and only create your widgets when you want to set them as central widget.

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

                  KiraK 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @Kira See https://doc.qt.io/qt-5/qmainwindow.html#setCentralWidget
                    "Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time."

                    I think if you set second widget as central widget the first one is automatically deleted as main window has the ownership. And if you then again try to set the first one it do4es not exist anymore and the pointer is invalid, hence the crash.
                    You can change your code and only create your widgets when you want to set them as central widget.

                    KiraK Offline
                    KiraK Offline
                    Kira
                    wrote on last edited by Kira
                    #9

                    @jsulm :Thanks for the clarification. I was looking at this as an approach to implement the functionality of replacing the widgets on a fly. But if this the issue, I think this approach cannot be applied.

                    I need to implement the below functionality:
                    InkedQtforum_LI.jpg elow functionality,
                    If I click on the project the contents on the right-hand side get refreshed
                    If I click on an example, I get a new set of widgets.

                    jsulmJ 1 Reply Last reply
                    0
                    • KiraK Kira

                      @jsulm :Thanks for the clarification. I was looking at this as an approach to implement the functionality of replacing the widgets on a fly. But if this the issue, I think this approach cannot be applied.

                      I need to implement the below functionality:
                      InkedQtforum_LI.jpg elow functionality,
                      If I click on the project the contents on the right-hand side get refreshed
                      If I click on an example, I get a new set of widgets.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Kira This is exactly what https://doc.qt.io/qt-5/qstackedwidget.html is doing.
                      Why don't you want to use it?

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

                      KiraK 1 Reply Last reply
                      2
                      • jsulmJ jsulm

                        @Kira This is exactly what https://doc.qt.io/qt-5/qstackedwidget.html is doing.
                        Why don't you want to use it?

                        KiraK Offline
                        KiraK Offline
                        Kira
                        wrote on last edited by
                        #11

                        @jsulm :
                        Thanks for the clarity and patience.
                        I went through the examples, and Stacked Widget is what I needed
                        I was trying to reimplement existing functionality.
                        Patient and helping people is what I love most about the forum.
                        Thanks once again.

                        1 Reply Last reply
                        2

                        • Login

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