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
Forum Updated to NodeBB v4.3 + New Features

Implementing multiple Screens

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 2 Posters 3.2k Views 1 Watching
  • 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.
  • K Kira
    30 Oct 2019, 06:48

    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.

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 30 Oct 2019, 07:20 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

    K 1 Reply Last reply 30 Oct 2019, 08:04
    1
    • J jsulm
      30 Oct 2019, 07:20

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

      K Offline
      K Offline
      Kira
      wrote on 30 Oct 2019, 08:04 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 ?

      J 1 Reply Last reply 30 Oct 2019, 08:07
      0
      • K Kira
        30 Oct 2019, 08:04

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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 30 Oct 2019, 08:07 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

        K 1 Reply Last reply 30 Oct 2019, 10:10
        0
        • J jsulm
          30 Oct 2019, 08:07

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

          K Offline
          K Offline
          Kira
          wrote on 30 Oct 2019, 10:10 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.

          J 1 Reply Last reply 30 Oct 2019, 11:44
          0
          • K Kira
            30 Oct 2019, 10:10

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

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 30 Oct 2019, 11:44 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

            K 1 Reply Last reply 31 Oct 2019, 05:33
            0
            • J jsulm
              30 Oct 2019, 11:44

              @Kira said in Implementing multiple Screens:

              because I am getting a lot of errors.

              Please post the errors

              K Offline
              K Offline
              Kira
              wrote on 31 Oct 2019, 05:33 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.

              J 1 Reply Last reply 31 Oct 2019, 05:38
              0
              • K Kira
                31 Oct 2019, 05:33

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

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 31 Oct 2019, 05:38 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

                K 1 Reply Last reply 31 Oct 2019, 05:59
                1
                • J jsulm
                  31 Oct 2019, 05:38

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

                  K Offline
                  K Offline
                  Kira
                  wrote on 31 Oct 2019, 05:59 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.

                  J 1 Reply Last reply 31 Oct 2019, 06:03
                  0
                  • K Kira
                    31 Oct 2019, 05:59

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

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 31 Oct 2019, 06:03 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

                    K 1 Reply Last reply 31 Oct 2019, 06:35
                    2
                    • J jsulm
                      31 Oct 2019, 06:03

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

                      K Offline
                      K Offline
                      Kira
                      wrote on 31 Oct 2019, 06:35 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

                      11/11

                      31 Oct 2019, 06:35

                      • Login

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