QWidget::normalGeometry incorrect
According to the documentation, QWidget::normalGeometry returns the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widget. However, when I maximize the window it returns the same value as QWidget::geometry, that is the size of a maximized window instead of its normal size. Could somebody explain this?
Re: QWidget::normalGeometry incorrect
If you are looking for a way to determine how much size a widget needs to display properly then the proper approach is to use sizeHint().
Re: QWidget::normalGeometry incorrect
Well, actually I need to know the rectangle occupied by the window in the normal state
Re: QWidget::normalGeometry incorrect
Before the user resizes it manually or after that?
Re: QWidget::normalGeometry incorrect
The best would be to know it always. I use it to restore the window size when it leaves fullscreen mode. If it was maximized before entering fullscreen mode, it can't be restored to the normal size after leaving fullscreen.
In general, let's say we maximized a window, how to know what size and position will it have when it gets back to normal?
Re: QWidget::normalGeometry incorrect
Quote:
Originally Posted by
mentalmushroom
The best would be to know it always.
There is no "always" as there is no "normal size". If you show a window, it has the size of its sizeHint(). If the user resizes it, it does not have that size anymore but rather the size set by the user. So which of the two do you consider "normal"?
Quote:
In general, let's say we maximized a window, how to know what size and position will it have when it gets back to normal?
I don't think the application has any way of knowing that. Window states are handled by the window manager and not the application. You can reimplement resizeEvent() for the window and store the new size whenever it changes so that you can track back to the previous size when needed.
Re: QWidget::normalGeometry incorrect
Quote:
There is no "always" as there is no "normal size". If you show a window, it has the size of its sizeHint(). If the user resizes it, it does not have that size anymore but rather the size set by the user. So which of the two do you consider "normal"?
Normal - the size a window has when it is not maximized, minimized or fullscreen. Once the user resized it, the normal size is the size set by the user.
Quote:
You can reimplement resizeEvent() for the window and store the new size whenever it changes so that you can track back to the previous size when needed.
Already tried that, but it's difficult to deal with window states, because resizeEvent is normally (or always?) called before window state is updated and it seems like when window was maximized via showMaximized it doesn't always have Qt::WindowMaximized flag in its state (maybe somehow related to previous geometry). I thought normalGeometry would return what I need, but it seems to return the same result as geometry does.
Anyway, thank you.
Re: QWidget::normalGeometry incorrect
When the window is maximized its state is undifferentiable from a window which get resized to a maximum size. As far as I understand it, when maximized the window is still in "normal" state, i.e. it is neither minimized nor full screen. Changing the window state is only a hint to the windowing system thus the control is very limited. You might need to revert to the native API to do what you require.
Re: QWidget::normalGeometry incorrect
Quote:
When the window is maximized its state is undifferentiable from a window which get resized to a maximum size.
I don't think so. When the window is maximized and the user clicks on the "restore" button of the window, it will go back to the size the window had before the maximization. That is why QT has to know the "normal size", otherwise it would not be able to go back.
This normal size is what the thread starter asked for and what "normalGeometry" should return and what should also be stored by saveGeometry() and also restored by restoreGeometry(). None of this works, though.
Edit: Ok, this thread is very old, I found it on google page 1 anyways and it still does not work.