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 pop a mainformwidget in and out of a Tab widget?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to pop a mainformwidget in and out of a Tab widget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 1.0k Views 3 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.
  • V visinet

    I have a QMainWindow window that I load into a tab of a QTabWidget in my application's main form and it works great, exactly what I want. Now I would like it to be possible to pop it and out of the tab, either by dragging it or via some other method, so it can be viewed on a different monitor if needed. Is this possible, and if so how? I have been looking for a solution to this for a couple of days but have yet to find one.

    Thank for any advice in advance.

    Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by
    #2

    @visinet

    How about you use QDockWidget?

    I'm also wondering how you have a QMainWindow inside a QTabWidget but maybe I dont understand your situation.


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    V 1 Reply Last reply
    2
    • Pl45m4P Pl45m4

      @visinet

      How about you use QDockWidget?

      I'm also wondering how you have a QMainWindow inside a QTabWidget but maybe I dont understand your situation.

      V Offline
      V Offline
      visinet
      wrote on last edited by visinet
      #3

      @Pl45m4
      Thanks for the response.

      What I am trying to do is basically implement how tabs work in most browsers and many other apps. Have a number of different windows open at the same time that can be either floating windows and dragged outside the application, or docked to a main top area of the applications main window and represented as tabs.

      I have tried using QDockWidgets and tabifying them which kinda works but IMO is clunky and not something I would consider delivering to a customer. The Tab widget way I have implemented and tested it is exactly how I want it to work if there is just some way to make it dock-able, or at least mimic that capability.

      Having a QTabWidget contain a QMainWindow, QDialog, or QWidget is easy.

      ui->tabWidget->addTab(new MyMainWindowForm1(),"MainForm");
      

      Thanks again for any insight you can provide.

      M 1 Reply Last reply
      0
      • V visinet

        @Pl45m4
        Thanks for the response.

        What I am trying to do is basically implement how tabs work in most browsers and many other apps. Have a number of different windows open at the same time that can be either floating windows and dragged outside the application, or docked to a main top area of the applications main window and represented as tabs.

        I have tried using QDockWidgets and tabifying them which kinda works but IMO is clunky and not something I would consider delivering to a customer. The Tab widget way I have implemented and tested it is exactly how I want it to work if there is just some way to make it dock-able, or at least mimic that capability.

        Having a QTabWidget contain a QMainWindow, QDialog, or QWidget is easy.

        ui->tabWidget->addTab(new MyMainWindowForm1(),"MainForm");
        

        Thanks again for any insight you can provide.

        M Offline
        M Offline
        mpergand
        wrote on last edited by
        #4

        @visinet
        I don't get the idea to have QMainWinow in a tab.

        What you can do :

        // get the widget of the tab
        QWidget* widget=tabWidget->widget(index);
        tabWidget->removeTab(index);
        // create a main window and set the central widget with it
        auto mainWindow=new MyMainWindow();
        mainWindow->setCentralWidget(widget);
        mainWindow->show();
        
        V 1 Reply Last reply
        1
        • M mpergand

          @visinet
          I don't get the idea to have QMainWinow in a tab.

          What you can do :

          // get the widget of the tab
          QWidget* widget=tabWidget->widget(index);
          tabWidget->removeTab(index);
          // create a main window and set the central widget with it
          auto mainWindow=new MyMainWindow();
          mainWindow->setCentralWidget(widget);
          mainWindow->show();
          
          V Offline
          V Offline
          visinet
          wrote on last edited by visinet
          #5

          @mpergand
          I may change it and use just a QWidget instead of QMainWindow if that works with the rest of the application. It appears it will, but that is just testing skeleton GUI code without any real functionality. That may change once I get to implementing the meat and potatoes of the application.

          The solution you proposed would work but the problem is that I don't want to have to destroy the window and create a new one every time it is docked/undocked. Each window may be communicating to one or more backend servers ( micro-services),not sure about that architecture yet, so not really liking that solution.

          Thanks again.

          M 1 Reply Last reply
          0
          • V visinet

            @mpergand
            I may change it and use just a QWidget instead of QMainWindow if that works with the rest of the application. It appears it will, but that is just testing skeleton GUI code without any real functionality. That may change once I get to implementing the meat and potatoes of the application.

            The solution you proposed would work but the problem is that I don't want to have to destroy the window and create a new one every time it is docked/undocked. Each window may be communicating to one or more backend servers ( micro-services),not sure about that architecture yet, so not really liking that solution.

            Thanks again.

            M Offline
            M Offline
            mpergand
            wrote on last edited by mpergand
            #6

            @visinet said in Is it possible to pop a mainformwidget in and out of a Tab widget?:

            Each window may be communicating to one or more backend servers ( micro-services)

            No need of QMainWindow for that.
            Anyway, I think you can set the parent to null before showing the window and it should work:

            // get the widget of the tab
            QWidget* widget=tabWidget->widget(index);
            tabWidget->removeTab(index);
            widget->setParent(nullptr);
            widget->show();
            
            V 1 Reply Last reply
            0
            • M mpergand

              @visinet said in Is it possible to pop a mainformwidget in and out of a Tab widget?:

              Each window may be communicating to one or more backend servers ( micro-services)

              No need of QMainWindow for that.
              Anyway, I think you can set the parent to null before showing the window and it should work:

              // get the widget of the tab
              QWidget* widget=tabWidget->widget(index);
              tabWidget->removeTab(index);
              widget->setParent(nullptr);
              widget->show();
              
              V Offline
              V Offline
              visinet
              wrote on last edited by
              #7

              @mpergand
              I was thinking along the same lines. From testing it looks like when you remove the tab the widget does not get destroyed so I am hoping it is as simple as this. Thanks again for the ideas and I will let you know the results once I get a chance to test it.

              V 1 Reply Last reply
              0
              • V visinet

                @mpergand
                I was thinking along the same lines. From testing it looks like when you remove the tab the widget does not get destroyed so I am hoping it is as simple as this. Thanks again for the ideas and I will let you know the results once I get a chance to test it.

                V Offline
                V Offline
                visinet
                wrote on last edited by
                #8

                @visinet
                Just tested it, couldn't wait for tomorrow, and it looks like it works perfect. I did it from the main window menu for simplicity so now all I have to do is see if I can actually do the same thing from the actual tab window I want to undock.

                void MainWindow::on_actionUndock_Current_triggered()
                {
                //    ui->tabWidget->widget(index)->close();
                    QWidget* widget=ui->tabWidget->widget(ui->tabWidget->currentIndex());
                    ui->tabWidget->removeTab(ui->tabWidget->currentIndex());
                    widget->setParent(nullptr);
                    widget->show();
                }
                
                

                A great way to end my Saturday. Now I can go out and have some fun and not be thinking about this all night.

                Thanks again for all your support.

                V 1 Reply Last reply
                0
                • V visinet

                  @visinet
                  Just tested it, couldn't wait for tomorrow, and it looks like it works perfect. I did it from the main window menu for simplicity so now all I have to do is see if I can actually do the same thing from the actual tab window I want to undock.

                  void MainWindow::on_actionUndock_Current_triggered()
                  {
                  //    ui->tabWidget->widget(index)->close();
                      QWidget* widget=ui->tabWidget->widget(ui->tabWidget->currentIndex());
                      ui->tabWidget->removeTab(ui->tabWidget->currentIndex());
                      widget->setParent(nullptr);
                      widget->show();
                  }
                  
                  

                  A great way to end my Saturday. Now I can go out and have some fun and not be thinking about this all night.

                  Thanks again for all your support.

                  V Offline
                  V Offline
                  visinet
                  wrote on last edited by
                  #9

                  @visinet
                  With regards to using QDockWidget, my main issue with it is that I want it use tab mode, which kinda works, but when I add a new QDockWidgets via

                  MainWIndow->addDockWidget(Qt::TopDockWidgetArea,dockWidgetWindowPtr)
                  

                  they get docked by default but they do not show up as a tabs, they show up as a docked widgets with title bar. I have to then manually drag them over an existing Docked Widget to get them tabbed without their header bars.

                  Any thought on this one?

                  Thanks once again.

                  JonBJ 1 Reply Last reply
                  0
                  • V visinet

                    @visinet
                    With regards to using QDockWidget, my main issue with it is that I want it use tab mode, which kinda works, but when I add a new QDockWidgets via

                    MainWIndow->addDockWidget(Qt::TopDockWidgetArea,dockWidgetWindowPtr)
                    

                    they get docked by default but they do not show up as a tabs, they show up as a docked widgets with title bar. I have to then manually drag them over an existing Docked Widget to get them tabbed without their header bars.

                    Any thought on this one?

                    Thanks once again.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #10

                    @visinet
                    I have not used dock widgets, or even seen what they look like, but does void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second)

                    Moves second dock widget on top of first dock widget, creating a tabbed docked area in the main window.

                    do what you want?

                    V 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @visinet
                      I have not used dock widgets, or even seen what they look like, but does void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second)

                      Moves second dock widget on top of first dock widget, creating a tabbed docked area in the main window.

                      do what you want?

                      V Offline
                      V Offline
                      visinet
                      wrote on last edited by
                      #11

                      @JonB
                      I thought that was what I was looking for but was confused by the fact that it has 2 widgets as its parameters and I could not find any examples of how to use it when there are more than 2 docks. I am going to play with it some more today to see if I can figure out if it will do what I want.

                      Thanks again.

                      V 1 Reply Last reply
                      0
                      • V visinet

                        @JonB
                        I thought that was what I was looking for but was confused by the fact that it has 2 widgets as its parameters and I could not find any examples of how to use it when there are more than 2 docks. I am going to play with it some more today to see if I can figure out if it will do what I want.

                        Thanks again.

                        V Offline
                        V Offline
                        visinet
                        wrote on last edited by
                        #12

                        @visinet
                        After some more playing with tabifyDockWidget, I got it figured out and working. I just always use the main/first dockwidget as the first parameter and the newly dynamically created dockwidget as the second. When I was originally looking at the tabifyDockWidget function I just wasn't understanding the concept.

                        Thanks again.

                        1 Reply Last reply
                        1

                        • Login

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