Results 1 to 5 of 5

Thread: How to get the width of a window frame, before showing any windows?

  1. #1
    Join Date
    Aug 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to get the width of a window frame, before showing any windows?

    Using Qt 4.7.4 with C++:

    Is there any way to get the width of the frame for a normal window, PRIOR to showing any windows? After showing a window, I know I can subtract the size() from the frameSize(), but that doesn't work until after the window is shown.

    I've looked at QApplication::style()->pixelMetric(), and I can get the height of the title bar using
    QApplication::style()->pixelMetric(QStyle::PM_TitleBarHeight)

    but I don't see any options to get the width of the rest of the border around the window.

    The only solution I've found so far is to:
    •set the window opacity to 0 (so the user doesn't see it),
    •show the window
    •then subtract size() from frameSize()

    Is there a better way?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to get the width of a window frame, before showing any windows?

    AFAIK you can't, since as long as the window is not shown, it doesn't have a size, as it could be it in a layout, or other influences take effect only at time when it is shown.
    However, I *think* if your intercept the show event, you might have valid size values in it, so it could spare you the opacity trick.
    But you have to test to make sure the geometry of the windows is valid at the show event it self.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: How to get the width of a window frame, before showing any windows?

    Can't you use resizeEvent()?
    Don't write a post just to thank someone, use "Thanks" button.

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get the width of a window frame, before showing any windows?

    what is the actual problem?

  5. #5
    Join Date
    Aug 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get the width of a window frame, before showing any windows?

    @amleto: When our app starts up, before displaying any windows, during the initialization of the main window, we calculate where we want the main window to be displayed. We want to restore it to its last position and size; however, we have to check that the position and size fit on the current monitors. The user may have fewer or different monitors connected, for instance.

    So, as part of our initialization of the main form, we read in the preferred position and size, then determine the appropriate monitor we'll be displaying on, and bound the preferred size to the available geometry of that monitor, and make sure the position is appropriate. We resize the window the final size we determined, and move the window to the final position we determined - all in the initialization process of the main window.

    We can assume the window title and frame will be normal (not a toolbox window frame, for example). We just need to know the dimensions of a normal window frame (which, of course, can differ by OS version/style), so our calculations, resize, and move will be accurate. We are aware of some issues with this on Mac and worse on Linux, but for now just trying to get this to work on Windows. I believe various versions or configurations of Windows can have different sizes for normal window frames, so we don't want to simply hard-code a value.

    David

Similar Threads

  1. Get window size prior to showing window?
    By mortoray in forum Qt Programming
    Replies: 0
    Last Post: 13th January 2011, 16:52
  2. Add a Frame Widget to the main window
    By kamlmish in forum Qt Programming
    Replies: 2
    Last Post: 30th November 2010, 08:51
  3. Window Frame of SubWindow
    By jcox23 in forum Qt Programming
    Replies: 0
    Last Post: 21st February 2010, 00:00
  4. qt4.6 webview has a window frame!!
    By billconan in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2009, 03:49
  5. Image without window frame?
    By niky in forum Qt Programming
    Replies: 6
    Last Post: 3rd February 2008, 09:37

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.