Is it possible to pop a mainformwidget in and out of a Tab widget?
-
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.
-
How about you use
QDockWidget
?I'm also wondering how you have a
QMainWindow
inside aQTabWidget
but maybe I dont understand your situation.@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.
-
@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.
@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();
-
@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();
@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.
-
@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.
@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();
-
@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();
@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. -
@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.@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.
-
@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.
@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 viaMainWIndow->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.
-
@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 viaMainWIndow->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.
@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?
-
@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?
@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.
-
@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.
@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.