wxWindow::SetSize and DPI Scaling

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
heinermueller
Experienced Solver
Experienced Solver
Posts: 69
Joined: Sat Oct 26, 2013 11:54 am

wxWindow::SetSize and DPI Scaling

Post by heinermueller » Wed Nov 18, 2015 2:59 pm

Hi all,

i can set a windows size ( i am talking about dialog items here ) using the wxWindow::SetSize method. Yet this method sets the size in pixels, which will be scaled on Windows when automatic pic scaling is active. There ary many places where a pixel size is used, SetMinSize() etc ...
What is the preferred way to handle this issue? The very best way would be to handle this by setting the size in Inches or centimeters, but this is not implemented.

Is there a practical solution to issue this available? I also face the problem that many dialogs are generated using wxglade - so the actual sizes are placed inside specific tags, so a code change there will be replaced by the wxglade code generator on the next dialog code generation.


I am using wx 3.0.2 under win 10 with a 4K screen with ca. 221 dpi, compiler is Visual Studio 2015.

All the best,

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWindow::SetSize and DPI Scaling

Post by doublemax » Wed Nov 18, 2015 4:04 pm

Using absolute pixel sizes for gui elements has always been bad. Can you tell your GUI editor to use "dialog units" instead? If yes that should solve the problem.
http://docs.wxwidgets.org/trunk/classwx ... 8a89ad0265

Otherwise you could add a custom "adjustforscreendpi()" call where ever you work with absolute pixel sizes.

Or you relayout the gui to use sizers instead and avoid absolute sizes.
Use the source, Luke!

heinermueller
Experienced Solver
Experienced Solver
Posts: 69
Joined: Sat Oct 26, 2013 11:54 am

Re: wxWindow::SetSize and DPI Scaling

Post by heinermueller » Thu Nov 19, 2015 3:56 pm

Or you relayout the gui to use sizers instead and avoid absolute sizes.
i am working 99% with sizers, but i want some controls like textctrl to have a mimnimal size, so i do either set the controls minimal size or the dialogs size, both using pixels. To be more precise, wxglade does it for me, but as told inside the tags, like eg:

Code: Select all

void mydialog::set_properties()
{
    // all inside this block will be overwritten =/
    // begin wxGlade: mxw_dialog_preload2playlist::set_properties
    SetTitle(_("dialog"));
    text_ctrl_titletext->SetMinSize(wxSize(200, 80));
    // end wxGlade

    // <---- so should i set again here?
    text_ctrl_titletext->SetMinSize(wxSize( dpi_factor()*200, dpi_factor()*80));
}

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWindow::SetSize and DPI Scaling

Post by doublemax » Thu Nov 19, 2015 5:47 pm

I don't know wxGlade, but looking for the manual i found this:
http://wxglade.sourceforge.net/manual/c ... es.section

There's an option "use dialog units by default...". Try setting this and see what code it generates for the SetMinSize().
Use the source, Luke!

heinermueller
Experienced Solver
Experienced Solver
Posts: 69
Joined: Sat Oct 26, 2013 11:54 am

Re: wxWindow::SetSize and DPI Scaling

Post by heinermueller » Thu Nov 19, 2015 7:20 pm

Now wxGlade uses dialog Units, indeed:

Code: Select all

SetSize(wxDLG_UNIT(this, wxSize(444, 451)));
Now i have to think about all this and how it affects my code .. =)
Thank you very much!

Post Reply