AddSubWindow
-
I have an application whose centralWidget is a QMdiArea and I am trying to add a new subwindow to the QMdiArea whenever someone clicks a button. The sample code I used to implement it is shown below. I see that the addSubWindow call adds new subwindows when I call it from the constructor of the MainWindow class but fails to show a new subwindow when I call it from the openNewTab slot. I am sure(using print statements) that addSubWindow method is called from openNewTab slot. I read the docs multiple times and it looks like this should work, but it doesn't. I am definitely doing missing something. Any pointers?
I am using latest Qt on a Macbook pro.
@
class MyMdiArea : public QMdiArea {slot:
void addSubWindow() {
widget = new QWidget();
addSubWindow(widget);
}
}class MainWindow : public QMainWindow
{
MainWindow::MainWindow()
{
myMdiArea = new MyMdiArea(this);
myMdiArea->addSubWindow(); //works
myMdiArea->addSubWindow(); //worksQToolBar *toolBar = addToolBar(tr("Navigation")); QAction* newTabAction = new QAction(tr("&New Tab"), this); newTabAction->setStatusTip(tr("Open a new Tab in this workspace")); toolBar->addAction(newTabAction); connect(newTabAction, SIGNAL(triggered()), SLOT(openNewTab())); toolBar->addWidget(locationEdit); setCentralWidget(mdiArea); setUnifiedTitleAndToolBarOnMac(true); }
//slot
void OpenNewTab() {
myMdiArea->addSubWindow(); // doesn't work
}
}
@ -
All widgets that you create need to be shown at some point. For your main window, you usually do that in your main() function. All child widgets automatically also get shown at that point. But for widgets you create later on in the life of the program, you need to do that explicitly.