PDA

View Full Version : Application with two MainWindows (switchable)



pothead42
2nd March 2017, 11:30
Hi folks,

I'm trying to write a new Gui (switchable) for a existing Qt-Application (V 4.8.4). So I Created a new QMainWindow (bisides the old one) and an other more QMainWindow two host the two MainWindows shown to the user. My Approach was to add them as centralWidget to "HostWidget".
the Problem is, that the other MainWindows are not the central widget of the "HostWidget" - it is just lying over it. Everthing else works fine however. So my Quastions are:

1) Is it possible to set a QMainWidget as a central widget. As far as I understand is a QMainWindow just a Widget with some bars and docking manager included.

2) I tried to add a stack widget and than added two MainWindows to this QStackWidget. But it is also not exactly what I want, since a StackWidget is intended to host widget whitch are already instanciated and conviniently switch them via index. However, no othe Window than one of the two Mainwindows are visible.

3) Or is there an other approach to create a gui with two Mainwindos that can be switched?

Thanks in advance

Santosh Reddy
2nd March 2017, 12:23
Lets say you want to host 2 (or multiple) MainWindows in a QMainWindow. Add the MainWindows to a layout, and then put this layout on a QWidget, set this QWidget as the central widget of QMainWidget.

I only problem I see that MainWindow will loose it's MenuBar, as it not a top level window anymore.

pothead42
2nd March 2017, 16:02
Thanks alot for your suggestion. I have got it work with approach 1). But I had to set the window flag of the Mainwindows to host as a central widget to Qt::Widget (using QMainWindow::setWindowFalg).
But now I have an onther Problem, that the hosted window is shown just after it is created but before it is set to be the central widget. So there is like a little "flicker" when I start the Application or switch the windows. Even if I trie to hide them before. The effect it also present, when I used approach 2) and abused the QStackedWidget for my job...

Santosh Reddy
3rd March 2017, 03:51
1). But I had to set the window flag of the Mainwindows to host as a central widget to Qt::Widget (using QMainWindow::setWindowFalg)
That should not be required.


Even if I trie to hide them before.
No need to hide, just don't show them in the first place, just add to layout and only show the host QMainWindow (top level window)