I am facing a problem, I have created an application using QmainWindow it is having tool bars, & statusbars. Now I have to add this application to another application which is derived from a another QMainWindow . Now I want to have my main Window inside this Main Window . How to do this Can we have QMainWindow inside Another QmainWindow or inside a QWidget? please hepl me .
Asked
Active
Viewed 5,177 times
5
-
So, you are trying to open a new window from your application? If so, you can follow these posts, they helped me a lot in achieving that: http://247jules.wordpress.com/2010/08/15/how-to-open-a-new-window-in-qt/ http://stackoverflow.com/questions/1518317/how-to-show-another-window-from-mainwindow-in-qt – Andrea Oct 28 '13 at 08:08
-
"Inside" as in having two separate main windows, or really a mainwindow nested in another window? – Frank Osterfeld Oct 28 '13 at 08:28
-
I want a nested mainwindow inside a mainwindow. – user2893054 Oct 28 '13 at 08:34
-
1What's a problem? Create an instance of your previously created QMainwindow subclass and place it on your second application's window layout. – VVV Oct 28 '13 at 08:49
2 Answers
7
I would write something like:
QMainWindow inside of another QMainWindow
QMainWindow *mainWindow = new QMainWindow;
QMainWindow *subWindow = new QMainWindow(mainWindow);
// .. some configuration
mainWindow->setCentralWidget(subWindow);
QMainWindow inside of a QWidget
QWidget *mainWindow = new QWidget;
QMainWindow *subWindow = new QMainWindow(mainWindow);
// .. some configuration
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(subWindow);
mainWindow->setLayout(layout);

vahancho
- 20,808
- 3
- 47
- 55
-
2For anyone chancing on this, you might want to also have `subWindow->setWindowFlags(Qt::Widget);`, `QMainWindow` by default has its window flag as `Qt::Window` which can cause some niggling issues. – iKlsR Oct 20 '17 at 02:34
-2
you can use this:
void QApplication::setActiveWindow(QWidget * active)
to set the widget (your main window) as the main window.

aaa
- 489
- 5
- 13