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. Is it possible to add a QmainWindow to another Qmainwindow/QWidget ?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to add a QmainWindow to another Qmainwindow/QWidget ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 7 Posters 4.7k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    While unusual, there's nothing stopping your from doing it.

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

    BhanuKiranChaluvadiB 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      While unusual, there's nothing stopping your from doing it.

      BhanuKiranChaluvadiB Offline
      BhanuKiranChaluvadiB Offline
      BhanuKiranChaluvadi
      wrote on last edited by
      #3

      Hi @SGaist

      In QmainWindow i have only

      addActions
      addDockWidget
      addToolBar

      there is nothing addQmainWindow ?

      How can i do that ?

      jsulmJ raven-worxR 2 Replies Last reply
      0
      • BhanuKiranChaluvadiB BhanuKiranChaluvadi

        Hi @SGaist

        In QmainWindow i have only

        addActions
        addDockWidget
        addToolBar

        there is nothing addQmainWindow ?

        How can i do that ?

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

        @BhanuKiranChaluvadi Like this?

        MainWindow w;
        w.show();
        

        There is no addMainWindow() because usually an application only has one main window. That's why it is called main window. As @SGaist already said it is unusual to create more than one main window. You can use QDialog for dialog windows or just QWidget for any other window.

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

        1 Reply Last reply
        0
        • BhanuKiranChaluvadiB BhanuKiranChaluvadi

          Hi @SGaist

          In QmainWindow i have only

          addActions
          addDockWidget
          addToolBar

          there is nothing addQmainWindow ?

          How can i do that ?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #5

          @BhanuKiranChaluvadi
          You can use a QMainWindow like any other QWidget. It just has some convenience features found in typical main windows.

          So use QMainWindow::setCentralWidget()

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          VRoninV 1 Reply Last reply
          1
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #6

            What you are you trying to do ? Can you give more info ? You may be trying something which is not a best practice. Your sample program would help.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            5
            • raven-worxR raven-worx

              @BhanuKiranChaluvadi
              You can use a QMainWindow like any other QWidget. It just has some convenience features found in typical main windows.

              So use QMainWindow::setCentralWidget()

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #7

              @raven-worx said:

              You can use a QMainWindow like any other QWidget. It just has some convenience features found in typical main windows.

              So use QMainWindow::setCentralWidget()

              Correct answer but a caveat: you'll have to call setWindowFlags(Qt::Widget); on the inner QMainWindow or it won't show up

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              raven-worxR 1 Reply Last reply
              1
              • VRoninV VRonin

                @raven-worx said:

                You can use a QMainWindow like any other QWidget. It just has some convenience features found in typical main windows.

                So use QMainWindow::setCentralWidget()

                Correct answer but a caveat: you'll have to call setWindowFlags(Qt::Widget); on the inner QMainWindow or it won't show up

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #8

                @VRonin said:

                Correct answer but a caveat: you'll have to call setWindowFlags(Qt::Widget); on the inner QMainWindow or it won't show up

                no, thats not true.
                Actually you would have to set the flag (Qt::Window) explicitly again if you want it the otherway around, since a reparenting happened.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                VRoninV 1 Reply Last reply
                1
                • raven-worxR raven-worx

                  @VRonin said:

                  Correct answer but a caveat: you'll have to call setWindowFlags(Qt::Widget); on the inner QMainWindow or it won't show up

                  no, thats not true.
                  Actually you would have to set the flag (Qt::Window) explicitly again if you want it the otherway around, since a reparenting happened.

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #9

                  @raven-worx

                  What I mean is the

                  QMainWindow sets the Qt::Window flag itself, and will hence always be created as a top-level widget.

                  from http://doc.qt.io/qt-5/qmainwindow.html#QMainWindow

                  So contrary to other QWidgets you have to undo this default to use it as a child widget

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  raven-worxR 1 Reply Last reply
                  1
                  • VRoninV VRonin

                    @raven-worx

                    What I mean is the

                    QMainWindow sets the Qt::Window flag itself, and will hence always be created as a top-level widget.

                    from http://doc.qt.io/qt-5/qmainwindow.html#QMainWindow

                    So contrary to other QWidgets you have to undo this default to use it as a child widget

                    raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by raven-worx
                    #10

                    @VRonin
                    no!
                    As i said, as soon as you add the second window the first one a reparenting is happening. So you do not have to change the window flags again.

                    Just try it yourself, and see that it is not correct.

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    1
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #11

                      hi
                      I inserted a mainwindow into the main window to fool around with Docks.
                      You need set nothing to allow it. Just put it in.
                      but as Dheerendra ask

                      Are you sure you need this?
                      If you give some details of the actual goal , maybe there is more
                      usual solution.

                      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