Search code examples
qtmdidockingqt5.5

All MDI windows are active


I am getting a weird issue. I have a few MDI windows in QMainWindow and catching windowStateChanged() in one of MDI to show/hide docking widget. Everything works fine here.

But if I try to put one of that window to dock (not adding it to mdiArea()) like this :

myMDIWindow->setWindowFlags(Qt::Widget | Qt::CustomizeWindowHint |
                            Qt::FramelessWindowHint);

// Create dock window and put my mdi window into it
QDockWidget *dock = new QDockWidget(myMDIWindow->windowTitle(), this);
dock->setFloating(true);
dock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
dock->setAllowedAreas(Qt::RightDockWidgetArea);
dock->setWidget(myMDIWindow);      // Wrap mdi window into dock
mainWindow()->addDockWidget(Qt::RightDockWidgetArea, dock);

then all other MDI windows become persistently active and I can't catch windowStateChanged signal. Converting MDI window to a simple widget does not help as well.

What could be the problem here? Is this a Qt bug?

New info: myMDIWindow with tree widget have signal connected to mdi window which creates it (Let's call it first mdi window). This signal connected to a slot which creates new MDI window according to user double-click in this tree widget. In this case all mdi windows become active. If I create MDI window by clicking a button in first mdi window - all become normal again. Code to create mdi window is the same in both cases:

  mdiArea->addSubWindow(newMDI);
  newMDI->setMainWindow(this);
  newMDI->show();
  newMDI->raise();
  mdiArea->setActiveSubWindow(newMDI);

"this" is main window. Could this be dock widget has focus or smth like this on mdi creation?

More info: if I undock window with tree widget all works fine again.


Solution

  • We found the cause:

    1st MDI window has QwtPlot for which we set focus:

    mUi->plot->setFocus();

    on creation. From my 1st MDI window I create a dock widget with tree widget in it. When user double-click an item in this tree widget,1st mdi window slot, connected to double-click signal, creates new MDI window. This 2nd MDI also contains QwtPlot which we set focus on as well on creation. All MDI windows become active in this case and I can't catch windowStateChanged signal.

    Now we commented all setFocus() calls, works fine now. What the problem could be here?