How to determine windowed geometry of QWindow while in maximized state?
-
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 - the window's geometry (as returned by
-
Hi,
When are you restoring the size/state when you start your application ?
-
@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. - A
-
@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. -
@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 byQWindow::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.