Re: What is the correct way to response to the wxEVT_DPI_CHANGED event?

Maarten Bent <[email protected]>
Newsgroups gmane.comp.lib.wxwindows.general
Message-ID <[email protected]>
Actually my comment about wxWindow::FromDIP is invalid. It shouldn't 
matter if you use wxWindow:: prefix.
I am not sure why using the Reset mode button results in a button with 
the wrong size. I cannot seem to reproduce this.

Maarten

On 30-3-2023 12:01, Maarten Bent wrote:
> Hi,
>
> In most cases you shouldn't have to do anything. The scaling is done 
> internally.
> If your own code has stuff that depend on the DPI, you can handle the 
> event and update things accordingly.
>
> FromDIP converts a device-independent size to the size applicable for 
> the display.
> So if your display has scaling 100% it converts 250x50 to 250x50 
> physical pixels
> If your display has 200% scaling, it converts 250x50 to 500x100 
> physical pixels.
> This ensures that it will look the same on both displays.
>
> In your example on the forum you use the static wxWindow::FromDIP() 
> function. This is incorrect. It will always use the DPI of the main 
> window when creating the control.
> This is why you see the wrong button size when you reset the 
> resolution and the button is recreated.
> You should use member function FromDIP() (without wxWindow::), so it 
> will use the DPI of the display that the window is shown on.
>
> wxDisplay::OnResetMode is definitely not needed for DPI changes.
>
> Maarten
>
> On 30-3-2023 07:52, AsmWarrior wrote:
>> Hi, when the application receive a wxEVT_DPI_CHANGED event, how can 
>> it response to the event?
>>
>> I looked at the wxWidgets' sample code "display", it looks like it 
>> does nothing, but just show some text in the status bar:
>>
>> void MyFrame::OnDPIChanged(wxDPIChangedEvent& event)
>> {
>>     wxLogStatus(this, "DPI changed: was %d*%d, now %d*%d",
>>                 event.GetOldDPI().x, event.GetOldDPI().y,
>>                 event.GetNewDPI().x, event.GetNewDPI().y);
>>
>>     event.Skip();
>> }
>>
>> But if we need to layout the UIs, do we need to call the ResetMode() 
>> function of the wxDisplay class?
>>
>> I just search for the "ResetMode" in wxWidgets' github site, I don't 
>> see much usage of this function.
>>
>> In the "display" sample code, this function is called when a wxButton 
>> get clicked.
>>
>> I even did some test about the DPI changing, and I think if 
>> ResetMode() is not called, the layout is wrong, you can see the 
>> discussion and image shots here in the:
>>
>> How does the FromDIP function work under different DPI scaling? — 
>> https://forums.wxwidgets.org/viewtopic.php?p=218156#p218156
>>
>> Any suggestions? Thanks!
>>
>> Asmwarrior
>> -- 
>> Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
>> ---
>> You received this message because you are subscribed to the Google 
>> Groups "wx-users" group.
>> To unsubscribe from this group and stop receiving emails from it, 
>> send an email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/wx-users/af6073ad-2ba0-43f8-94d2-d2c156fa6bcfn%40googlegroups.com 
>> <https://groups.google.com/d/msgid/wx-users/af6073ad-2ba0-43f8-94d2-d2c156fa6bcfn%40googlegroups.com?utm_medium=email&utm_source=footer>.
>

-- 
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
--- 
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/08e1e354-231a-131e-1a43-8c63ca215e3d%40gmail.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.