Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

MdiSubwindows when minimized and restored don't have same position.



  • Hey Qt Devs

    I created 2 widgets, then put them into QMdiArea by QMdiArea::addSubwindow(QWidget *widget). The trick I wish to archive is to minimize 2nd subwindow when I'm minimizing the 1st one, and restore it as well. Do to that, I've written code:

    void My1stWidget::changeEvent(QEvent *event)
    {
        event->accept();
        QWidget::changeEvent(event);
        if (event->type() == QEvent::WindowStateChange && addEquipmentDialog)
        {
            if (isMinimized())
            {
                //emit minimizeAddNewEquipmentDialog();
                addEquipmentDialog->showMinimized();//that's 2nd widget
            }
            else
            {
                //emit restoreAddNewEquipmentDialog();
                addEquipmentDialog->showNormal();
            }
        }
    }
    

    Works fine, except the 1st widget is not restored to the same position on QMdiArea it had before minimizing. If I minimize the widgets separately they restore to correct positions.
    What I'm doing wrong, or what knowledge I'm missing?

    Qt 5.11.2, mingw32 compiler.


  • Lifetime Qt Champion

    Hi,

    Since you call accept on the event, it will not be further processed when calling the base class implementation. so you should likely remove that line.



  • Unfortunetly @SGaist it didn't helped :/
    Well, more information. The 2nd widget(the one with red close buttons) at the beginning is a child of 1st widget
    0_1556872099353_Screen 1.PNG

    Then it is switched to independent window, and looks like this:
    1_1556872099354_Screen 2.PNG
    Code which does the switch:

    void AddEquipmentItem::switchToFloatingMode(bool turnOn)
    {
        if (turnOn)
        {
            if (!floatingWindow)
            {
                floatingWindow = area->addSubWindow(this);
                floatingWindow->setWindowFlags(Qt::Widget | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowStaysOnTopHint);
                floatingWindow->setWindowFlag(Qt::WindowSystemMenuHint, false);
                floatingWindow->setFixedWidth(this->width() + 8);
            }
            else
            {
                floatingWindow->setWidget(this);
            }
            floatingModeButton->setToolTip("Switch to docked mode");
            floatingModeButton->setIcon(dockedIcon);
            floatingWindow->show();
        }
        else
        {
            floatingWindow->setWidget(nullptr);
            floatingWindow->hide();
    
            setParent(parentWidget);//parent widget is the 1st widget
    
            floatingModeButton->setToolTip("Switch to floating mode");
            floatingModeButton->setIcon(floatingIcon);
    
            setGeometry(geometryRectangle);
            initAndShow(mechPart);
            move(anchorPoint);
        }
    }
    

    And the bug - after minimizing, then restoring the main widget its position should be like on the screen above - yet it isn't
    2_1556872099354_Screen 3.PNG


  • Lifetime Qt Champion

    What's that geometryRectangle variable ?



  • geometryRectangle is used to position 2nd widget when in docked mode - as you can see on 1st screen shot.


  • Lifetime Qt Champion

    I meant: where does it come from.

    Looks like only the top is not aligned with your other widget's geometry.



  • That geometryRectangle is irrelevant, as it is used only for the widget with 2 large, red close buttons which is positioned correctly. What I observed via debugging/logging is that code part:

            if (isMinimized())
            {
                //emit minimizeAddNewEquipmentDialog();
                addEquipmentDialog->showMinimized();//that's 2nd widget
            }
    

    somehow spoils behavior of the widget, if I recall correctly after manual, separate minimizing call showNormal() simultaneously worked fine for both widgets. Need to confirm that after work, though.