Results 1 to 9 of 9

Thread: QWidget::normalGeometry incorrect

  1. #1
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default 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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QWidget::normalGeometry incorrect

    Well, actually I need to know the rectangle occupied by the window in the normal state

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWidget::normalGeometry incorrect

    Before the user resizes it manually or after that?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default 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?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWidget::normalGeometry incorrect

    Quote Originally Posted by mentalmushroom View Post
    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"?

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QWidget::normalGeometry incorrect

    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.

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    mentalmushroom (12th September 2013)

  10. #9
    Join Date
    Nov 2013
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QWidget::normalGeometry incorrect

    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.

Similar Threads

  1. Incorrect Julian Day
    By Rayven in forum Qt Programming
    Replies: 6
    Last Post: 16th November 2011, 14:10
  2. QMake Incorrect Makefile generated
    By Octal in forum Qt Tools
    Replies: 7
    Last Post: 19th March 2011, 16:05
  3. Incorrect position of QPushButton on mac
    By francis in forum Qt Programming
    Replies: 4
    Last Post: 1st March 2011, 18:34
  4. Incorrect mouse behavior in GraphicsScene
    By framalex in forum Newbie
    Replies: 9
    Last Post: 12th June 2010, 00:43
  5. QRegExp matchedLength seems incorrect
    By Arjan in forum Qt Programming
    Replies: 5
    Last Post: 16th July 2009, 19:03

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.