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. How to determine windowed geometry of QWindow while in maximized state?
QtWS25 Last Chance

How to determine windowed geometry of QWindow while in maximized state?

Scheduled Pinned Locked Moved Solved General and Desktop
windowgeometrymaximized
6 Posts 4 Posters 857 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.
  • P Offline
    P Offline
    Phoenox
    wrote on 9 Mar 2021, 16:52 last edited by
    #1

    Hello everyone,

    I'm currently trying to persist the state of a window.
    Currently, I'm storing

    • the window's geometry (as returned by QWindow::geometry())
    • the window states (as returned by QWindow::windowStates())

    When I resize a window and maximize it, if I then "unmaximize" it (what's the correct term for this BTW?), it gets the geometry it had before. That's nice.

    Now for my actual use case: I resize and maximize like before, and now store the window's state.
    When I now restart my application and restore the window's state, it's maximized (as expected). However, when I now "unmaximize" it, it has a different geometry than it had at the start (before maximizing and storing).

    Is there a way to access this missing geometry (and set it)? Or is this something that the window manager itself does, and Qt has no way of accessing it?

    Cheers
    PhoeNox

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Mar 2021, 19:32 last edited by
      #2

      Hi,

      When are you restoring the size/state when you start your application ?

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

      P 1 Reply Last reply 9 Mar 2021, 21:27
      0
      • J Offline
        J Offline
        JoeCFD
        wrote on 9 Mar 2021, 20:35 last edited by
        #3

        use qsettings to save the window sizes and you will always have the same ones.

        1 Reply Last reply
        0
        • S SGaist
          9 Mar 2021, 19:32

          Hi,

          When are you restoring the size/state when you start your application ?

          P Offline
          P Offline
          Phoenox
          wrote on 9 Mar 2021, 21:27 last edited by
          #4

          @SGaist I'm not sure what you're aiming at, so I'll try my best to give you more context:

          I have a "main window" that can certain spawn child windows, QQuickViews to be precise.
          When such a window is spawned, the following happens:

          • A QQuickView is created
          • Title and icon are being set
          • the size/states are set <== This is the interesting part
          • the QML source is set
          • the QQuickView is shown

          However, I don't think that it's just the restoring.
          I mean, I can see the data that is being saved, and the stored geometry is that of a window filling the whole screen, because at the moment of storing, the window is maximized. What I need is a way of retrieving the windowed window size while the window is maximized.

          P 1 Reply Last reply 10 Mar 2021, 01:44
          0
          • P Phoenox
            9 Mar 2021, 21:27

            @SGaist I'm not sure what you're aiming at, so I'll try my best to give you more context:

            I have a "main window" that can certain spawn child windows, QQuickViews to be precise.
            When such a window is spawned, the following happens:

            • A QQuickView is created
            • Title and icon are being set
            • the size/states are set <== This is the interesting part
            • the QML source is set
            • the QQuickView is shown

            However, I don't think that it's just the restoring.
            I mean, I can see the data that is being saved, and the stored geometry is that of a window filling the whole screen, because at the moment of storing, the window is maximized. What I need is a way of retrieving the windowed window size while the window is maximized.

            P Offline
            P Offline
            Pl45m4
            wrote on 10 Mar 2021, 01:44 last edited by Pl45m4 3 Oct 2021, 01:48
            #5

            @Phoenox said in How to determine windowed geometry of QWindow while in maximized state?:

            What I need is a way of retrieving the windowed window size while the window is maximized.

            That's impossible, AFAIK (unless you save it before).
            How should your app know, when in maximized state, what your desired windowed size for one specific window is?! You need to save the size before, maximize and then you can restore it back to your default (and saved) window size.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            P 1 Reply Last reply 11 Mar 2021, 18:41
            1
            • P Pl45m4
              10 Mar 2021, 01:44

              @Phoenox said in How to determine windowed geometry of QWindow while in maximized state?:

              What I need is a way of retrieving the windowed window size while the window is maximized.

              That's impossible, AFAIK (unless you save it before).
              How should your app know, when in maximized state, what your desired windowed size for one specific window is?! You need to save the size before, maximize and then you can restore it back to your default (and saved) window size.

              P Offline
              P Offline
              Phoenox
              wrote on 11 Mar 2021, 18:41 last edited by Phoenox 3 Nov 2021, 18:42
              #6

              @Pl45m4 I thought as much. As to the question how the app should know: Well, the window manager knows, and Qt should be my adapter to the system's window manager. But I do agree that it's something one doesn't need very often.

              I've now implemented a workaround: I've subclassed the QQuickView and connect a slot to the following signals:

              • QWindow::xChanged()
              • QWindow::yChanged()
              • QWindow::widthChanged()
              • QWindow::heightChanged()

              In the slot, I first check if the window is in maximized state. If not, I store the current window geometry.
              When persisting the window state, I store the geometry stored in this subclass, not the one returned by QWindow::geometry().

              When I restore, I can first set the geometry and then open it in maximized state. When I now unmaximize it, I get desired geometry.

              In any case, thanks for helping me out and confirming that this cannot be accessed directly through Qt's interface.

              1 Reply Last reply
              0

              1/6

              9 Mar 2021, 16:52

              • Login

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