[wxMSW][wx3.0.2] Handling layout issues on different screen resolution Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

[wxMSW][wx3.0.2] Handling layout issues on different screen resolution

Post by Rudra »

Hi,

In my wx application, when I create widgets with given height and width, it appears differently on versions of win OS with higher screen resolution. The widgets come with small size on win 8/10. I use to work on win-7, it looks as expected on it, but on win-8/10 it is worse. I dig into it and found that if I give the relative height/width then it works.

I don't find what to do in case of wxDataViewListCtrl. If I provide the width of the columns then I get the same issue, otherwise, column comes equal in size.

Please help!

Thanks,
R.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: [wxMSW][wx3.0.2] Handling layout issues on different screen resolution

Post by ONEEYEMAN »

Hi,
What you should do is use sizers for laying out controls and supply "wxDefaultPosition, wxDefaultSize" as position and size to the control constructor.
See Sizers overview, layout sample and multiple link that explain how to use sizers on the web.

Thank you.

P.S.: Even though providing the position and size is supported, when you work in cross-platform environment the positioning and sizes of controls/frames will be different depending on the font sizes, screen resolutions and a lot of different things.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wxMSW][wx3.0.2] Handling layout issues on different screen resolution

Post by doublemax »

The actual screen resolution is probably not relevant, it's a higher GUI scaling in the Windows settings. Did you mark your application as "dpi aware"?

As already mentioned, using absolute pixel values should be avoided if possible. But there are situations where it can't be avoided. In that cases you need to scale the pixel value according to the current DPI of the display. wxWidgets 3.1.x has new methods for that, e.g. wxWindow::ToDIP(), wxWindow::FromDIP
http://docs.wxwidgets.org/trunk/classwx ... 257e09d123

If you have to use wx 3.0.2, you can use (double)wxGetDisplayPPI() / 96.0f as scale factor.
http://docs.wxwidgets.org/trunk/group__ ... 3eba457cfa
Use the source, Luke!
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wxMSW][wx3.0.2] Handling layout issues on different screen resolution

Post by Rudra »

Thanks for the reply.
ONEEYEMAN wrote:Hi,
What you should do is use sizers for laying out controls and supply "wxDefaultPosition, wxDefaultSize" as position and size to the control constructor.
I did same to fix most of the layout issues but can't use same for widgets like wxDataViewListCtrl in which I want to get columns with different size.
doublemax wrote: If you have to use wx 3.0.2, you can use (double)wxGetDisplayPPI() / 96.0f as scale factor.
Can you please explain how to use this? If I want to width 50 of a column. Then value should be like,

Code: Select all

double scaleFacX = wxGetDisplayPPI().GetWidth()/96.0f;
int w = 50;
w /=  scaleFacX;
is that ok?

Please suggest!

Thanks,
R.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wxMSW][wx3.0.2] Handling layout issues on different screen resolution

Post by doublemax »

You need to multiply, you want the value to get bigger on screens with higher dpi.

Code: Select all

double scaleFacX = (double)wxGetDisplayPPI().GetWidth() / 96.0f;
int w = 50 * scaleFacX ;
Use the source, Luke!
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wxMSW][wx3.0.2] Handling layout issues on different screen resolution

Post by Rudra »

On my win-7, the scaleFacX comes 0.73958333333333337. So,

Code: Select all

int w = 50 * scaleFacX ;
gives 37.98 which gives even small size on my os.

If I want to see what I see when passing 50 in width, I have to supply 67.60*scaleFacX .

Please correct!

Thanks,
R.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wxMSW][wx3.0.2] Handling layout issues on different screen resolution

Post by doublemax »

I have no explanation for this, AFAIK it's not possible in Windows to set a UI scaling less than 100%, so it should be impossible that wxGetDisplayPPI().x returns anything smaller than 96.

Is your exe marked as "dpi aware" through the manifest or VisualStudio setting (if you use that) ?
Use the source, Luke!
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wxMSW][wx3.0.2] Handling layout issues on different screen resolution

Post by Rudra »

No, I never set "dpi aware". I don't know to set.
I see that the wxGetDisplaySize() returns size(1366, 768) and wxGetDisplaySizeMM() returns size(482, 271). So, wxGetDisplayPPI() returns size(71, 71),

Code: Select all

wxSize wxGetDisplayPPI()
{
    const wxSize pixels = wxGetDisplaySize();
    const wxSize mm = wxGetDisplaySizeMM();

    return wxSize((int)((pixels.x * inches2mm) / mm.x),
                  (int)((pixels.y * inches2mm) / mm.y));
}
Not sure what to do here.
Thanks,
R.
Manolo
Can't get richer than this
Can't get richer than this
Posts: 828
Joined: Mon Apr 30, 2012 11:07 pm

Re: [wxMSW][wx3.0.2] Handling layout issues on different screen resolution

Post by Manolo »

You should tell what "size" means:
a) Absolute pixels
b) Absolute inches or milimeters
c) A percentaje of the screen or of the parent window
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wxMSW][wx3.0.2] Handling layout issues on different screen resolution

Post by doublemax »

No, I never set "dpi aware". I don't know to set.
You should definitely do that. This could be a root problem.

If you are using a recent version of Visual Studio, you can set it under Configuration Properties -> Manifest Tool -> Input and Output -> DPI Awareness

Otherwise you have to edit the application manifest yourself.
https://msdn.microsoft.com/en-us/librar ... N_MANIFEST

Also, try this method to get the logical DPI:

Code: Select all

int getWindowsLogicalDPI()
{
	HDC screen = GetDC(NULL);
	double hDpi = GetDeviceCaps(screen,LOGPIXELSX);
	ReleaseDC(NULL, screen);

	return (int)hDpi;
}
Use the source, Luke!
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wxMSW][wx3.0.2] Handling layout issues on different screen resolution

Post by Rudra »

doublemax wrote:You should definitely do that. This could be a root problem.

If you are using a recent version of Visual Studio, you can set it under Configuration Properties -> Manifest Tool -> Input and Output -> DPI Awareness

Otherwise you have to edit the application manifest yourself.
https://msdn.microsoft.com/en-us/librar ... N_MANIFEST
This fixes the issue. Thanks for the help!

Thanks,
R.
Post Reply