Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. MdiSubwindows when minimized and restored don't have same position.

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmdisubwindowqmdiareaminimize
7 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MasterBLBM Offline
    MasterBLBM Offline
    MasterBLB
    wrote on last edited by MasterBLB
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • MasterBLBM Offline
        MasterBLBM Offline
        MasterBLB
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What's that geometryRectangle variable ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • MasterBLBM Offline
            MasterBLBM Offline
            MasterBLB
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I meant: where does it come from.

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • MasterBLBM Offline
                MasterBLBM Offline
                MasterBLB
                wrote on last edited by MasterBLB
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved