QMainWindow as a child of QMainWindow
Is is possible at all ? I have to implement a very special layout, where only the part of main window must have ability to manage dock widgets (and it is not implementable in terms of dock areas). The problem is in crash when I trying to add dock widget to child QMainWindow. Any ideas?
Re: QMainWindow as a child of QMainWindow
Yes, it's possible. QMainWindow is not limited to one instance and it can be placed into layout like any other widget (even though it might not lead to the most intuitive user interface...)
Re: QMainWindow as a child of QMainWindow
Quote:
Originally Posted by
jpn
Yes, it's possible. QMainWindow is not limited to one instance and it can be placed into layout like any other widget (even though it might not lead to the most intuitive user interface...)
I've made one more sample project where I have two main window and one dock widget but for some reason I can only see the top-level mainwindow.
Here is what I do:
Code:
QMainWindowTest
::QMainWindowTest(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi(this);
w
->addDockWidget
(Qt
::LeftDockWidgetArea,
new QDockWidget(""));
}
Re: QMainWindow as a child of QMainWindow
You're not adding the "child main window" to any layout.
Re: QMainWindow as a child of QMainWindow
Quote:
Originally Posted by
jpn
You're not adding the "child main window" to any layout.
It must not be the reason. When I added for example QLineEdit the same way - I could see it. It seems second QMainWindow still doesn't have a parent. Anyway I prepared test sample, which uses layout for second QMainWindow - no luck. Here is a code:
Code:
#include <QtGui/QApplication>
#include <QHBoxLayout>
#include <QMainWindow>
#include <QDockWidget>
int main(int argc, char *argv[])
{
w.setLayout(l);
m->addDockWidget(Qt::RightDockWidgetArea, d);
l->addWidget(m);
w.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
But if I call "m->show()" I can see second main window as a second top-level widget. Maybe I need to tweak some window flags to get second mainwindow to become a child.
Re: QMainWindow as a child of QMainWindow
You can't install a layout on QMainWindow. QMainWindow has its own special layout which contains the central widget, docks widgets, toolbars etc. Set one main window as others central widget or install the layout on a widget which you set as central widget.
Re: QMainWindow as a child of QMainWindow
I faced the same problem, but seems solved thanks to this page :
Code:
#include <QApplication>
#include <QMainWindow>
#include <QDockWidget>
#include <QTextEdit>
#include <QToolBar>
#include <QAction>
int main(int argc, char *argv[])
{
// Application QMainWindow
mainWindow->setWindowTitle("MainWindow") ;
mainWindow
->setCentralWidget
(new QTextEdit("Hello Main World!")) ;
mainWindow->addDockWidget(Qt::RightDockWidgetArea, dock);
toolbar1
->addAction
(new QAction("FirstOne",
0)) ;
mainWindow->addToolBar(toolbar1) ;
toolbar2
->addAction
(new QAction("SecondOne",
0)) ;
mainWindow->addToolBar(toolbar2) ;
// another QMainWindow you want to embed
subMainWindow->setWindowTitle("sub-mainwindow") ;
subMainWindow
->setCentralWidget
(new QTextEdit("Hello Submain World!")) ;
toolbar3
->addAction
(new QAction("ThirdOne",
0)) ;
subMainWindow->addToolBar(toolbar3) ;
// embed :
dock->setWidget(subMainWindow) ;
subMainWindow->setParent(dock) ; // here
mainWindow->show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
Re: QMainWindow as a child of QMainWindow
You aren't doing the same thing as the original poster. He was trying to add the new QMainWindow as a direct child of the top-level QMainWindow. You are adding it as the main widget of a dock window.
In your case, you are following all of the QMainWindow "rules" even though the effect is different. It isn't really clear what the OP intended his GUI to look like. Maybe he wanted another main window that floats or docks like yours will.
I am guessing that what he wants is what Microsoft calls an "MDI" or "multiple document interface" app, where you can have several child windows within a main window frame. The menu, toolbars, and other main window components control whichever child window has focus.
But this is a 3-year-old post, so I am guessing that he either solved his problem or gave up.
Re: QMainWindow as a child of QMainWindow
Maybe you're right yes :) I did not get his point in first posts
I was actually referring to his answer in post #5
Quote:
Originally Posted by Elder Orb
But if I call "m->show()" I can see second main window as a second top-level widget. Maybe I need to tweak some window flags to get second mainwindow to become a child.
I met the same issue, and solved it the way I precised. I only unburried this 3-years old post to help people looking for an answer because it was a problem for me, even 3 years later