PDA

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



davidb
14th September 2011, 14:29
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?

high_flyer
15th September 2011, 09:49
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.

Rachol
15th September 2011, 10:48
Can't you use resizeEvent()?

amleto
15th September 2011, 11:16
what is the actual problem?

davidb
15th September 2011, 14:09
@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