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. Force resize of window when geometry is the same?
Forum Updated to NodeBB v4.3 + New Features

Force resize of window when geometry is the same?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 2 Posters 2.5k Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    Qt_User72653
    wrote on last edited by
    #1

    I have a frameless window that I'm maximizing then restoring, but I'm having an issue with the window size not being restored properly if it's greater than the monitor it was maximized in in a dual monitor setup.

    My solution was to store the geometry before it was maximized then restore it when the window itself is restored. The problem is that the window ignores a resize if the geometry is the same, so my solution is to make the width one pixel wider then immediately set the geometry back:

    QWidget::window()->resize(m_normal_rect.width() + 1,
        m_normal_rect.height());
    QWidget::window()->resize(m_normal_rect.size());
    

    Is there a way to force the geometry to update even if it's the same as the current geometry?

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

      Hi,

      Do you mean that your user can resize that frameless window ?

      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
      • Q Offline
        Q Offline
        Qt_User72653
        wrote on last edited by
        #3

        Yes, it's a frameless window being used to create a window with a custom style.

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

          How do they resize it ?

          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
          • Q Offline
            Q Offline
            Qt_User72653
            wrote on last edited by Qt_User72653
            #5

            Like a normal window, using the mouse cursor and dragging it.

            Edit: Which is functionality that I added. When the user clicks+drags, I call window()->setGeometry(...) with the updated geometry.

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

              Then the silly question: why do you to resize if your widget already has the correct size on maximisation ?

              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
              • Q Offline
                Q Offline
                Qt_User72653
                wrote on last edited by
                #7

                Because if the normal geometry's width is greater than the width of the monitor that it was maximized on, when it's restored the window is truncated to the width of the monitor. The first resize forces setGeometry_sys(...) to actually resize the window, then the second resize returns it to it's correct size.

                The real issue is that the restored window isn't restoring to it's correct size, but I haven't found a way to fix that so the resizing is just a workaround.

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

                  Then why not use QDesktopWidget::screenGeometry and use it to ensure your resize is done using the best value possible ?

                  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
                  • Q Offline
                    Q Offline
                    Qt_User72653
                    wrote on last edited by
                    #9

                    What do you mean best value?

                    I use the screen geometry to set the maximized size (using win32 functions).

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

                      How are you doing that ?

                      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
                      • Q Offline
                        Q Offline
                        Qt_User72653
                        wrote on last edited by
                        #11

                        In a nativeEventFilter I check for a WM_GETMINMAXINFO message, and do this:

                            auto maximize_dimensions = reinterpret_cast<::MINMAXINFO*>(msg->lParam);
                            auto rect = QApplication::desktop()->availableGeometry(this);
                            maximize_dimensions->ptMaxSize.x = rect.width();
                            maximize_dimensions->ptMaxSize.y = rect.height() - 1;
                            maximize_dimensions->ptMaxPosition.x = 0;
                            maximize_dimensions->ptMaxPosition.y = 0;
                        

                        Which is used to properly maximize the window in all monitors on a multiple monitor setup.

                        Then on state changes:

                            if(event->type() == QEvent::WindowStateChange) {
                              auto state_change_event = static_cast<QWindowStateChangeEvent*>(event);
                              if(!state_change_event->oldState().testFlag(Qt::WindowMaximized)
                                  && QWidget::window()->isMaximized()) {
                                m_normal_rect = QWidget::window()->frameGeometry();
                              } else if(state_change_event->oldState().testFlag(Qt::WindowMaximized) &&
                                  !QWidget::window()->isMaximized()) {
                                QWidget::window()->resize(m_normal_rect.width() + 1,
                                  m_normal_rect.height());
                                QWidget::window()->resize(m_normal_rect.size());
                              }
                            }
                        

                        Which fixes the issue I mentioned in posts 1 and 7 when restoring the window. I couldn't find a way to fix it using the Windows' API, so my double resize method is how I've fixed it.

                        I should have mentioned that when I get the window geometry after the window is restored, it gives me the correct size, but Windows isn't showing the window at that size. There's something in resizing the window that fixes the size discrepancy between the system window and Qt's window.

                        1 Reply Last reply
                        0
                        • Q Offline
                          Q Offline
                          Qt_User72653
                          wrote on last edited by
                          #12

                          So is there no way to force a resize of a window?

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

                            Well, forcing a resize means that you have to change it at some point.

                            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

                            • Login

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