Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    qmdisubwindow qmdiarea minimize
    2
    7
    655
    Loading More Posts
    • 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.
    • MasterBLB
      MasterBLB last edited by MasterBLB

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • MasterBLB
          MasterBLB last edited by

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • MasterBLB
              MasterBLB last edited by

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

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 0
                • MasterBLB
                  MasterBLB last edited by MasterBLB

                  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 Reply Quote 0
                  • First post
                    Last post