Using wxSizers on high dpi, positions the widgets differently then on low dpi

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.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ONEEYEMAN »

Hi,
Why do you want to hardcode anything? Its ugly and it breaks!!

Use sizers - they will make life soooo much easier!!

Thank you.
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ibrahim »

Thats because I need to either change the width or height for a widget.

I am trying to use sizers >:(

My "wxCheckListBox" could have different items in it for different executions , so if it had over 100 items in it , the "wxCheckListBox" would become so big that it would go past the screen , thats why I need a fixed size. So in this case they don't make life easier :( .

Can't there be a class like wxSize , but it corresponds to the same size on every major platform. For Example , some like a "wxGenericSize".
Last edited by ibrahim on Wed May 25, 2022 2:33 pm, edited 1 time in total.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ONEEYEMAN »

Hi,
No you don't.
You may think that you do because you are coming from the M$ paradigm that everything has to be hardcoded.

Now, there is no layout that can not be coded with sizers.

All you need to remember is - sizers use minimal size to lay out control and it is their best size.

Thank you.

P.S.: If you can show me a layout where a size has to be hardcoded, I will buy you a beer...
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ibrahim »

Is setting the minimal size gonna destory cross-platform safety ?????????

Is the minimal size gonna be different on every platform ???????


Thats what I asked since the beginning , I'm not understanding how this best size stuff is related to what I asked.
I need to use a minimal size , so thats why I'm asked this question :evil:
Last edited by ibrahim on Wed May 25, 2022 2:43 pm, edited 1 time in total.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ONEEYEMAN »

Hi,
Can you explain in plain English why do you insist on hardcoding position/size?
Using sizers is so much easier and pain free...

No modern toolkit does it.

Thank you.
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ibrahim »

PLEASE READ MY ENTIRE POST



I am not hardcoding the position


This is what would happen is I just carelessly let the sizer get the best size for the wxCheckListBox :
My "wxCheckListBox" could have different items in it for different executions , so if it had over 100 items in it , the "wxCheckListBox" would become so big that it would go past the screen , thats why I need a fixed size. So in this case they don't make life easier :( .
If your saying its possible to change the width and height of a widget without hardcoding the sizes , why don't you tell me how ??

Also Is setting the SetMaxSize() count as hardcoding , doublemax told me to use it to decrease the widgets size.
I'm using SetMinSize() to increase the widgets size ( Opposite of SetMaxSize() ) .

Also have you read my post where I mention "wxGenericSize" , where the size passed in corresponds to the same size of every platform.

I'm not hardcoding any position , I'm letting the wxFlexGridSizer take care of that for me

Is using SetMaxSize() hardcoding ?? Is using SetMinSize() hardcoding ?? if yes then how do I change the size using those functions.
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by doublemax@work »

I think you already have all the information you need. Sometimes it's necessary to limit the size of a control for UX reasons, and you can use SetMaxSize() to do that. E.g. for the checklistbox, only limit the height, so that the control can still grow in its width direction.
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ibrahim »

Okay , I've changed the wxCheckListBox to only limit the height that and It works , Thanks for all the help, ONEYEEMAN made me think all of this sizer stuff was for nothing :( . I'll try to solve the third question myself :D

Edit :


I've solved the third question myself , thanks for helping me , I'll accept your latest post as the answer :D

Edit 2 :

For some reason , on high dpi the font is smaller , all the sizes are correct , but the font is smaller.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ONEEYEMAN »

Hi,
ibrahim wrote: Wed May 25, 2022 2:45 pm PLEASE READ MY ENTIRE POST



I am not hardcoding the position


This is what would happen is I just carelessly let the sizer get the best size for the wxCheckListBox :
My "wxCheckListBox" could have different items in it for different executions , so if it had over 100 items in it , the "wxCheckListBox" would become so big that it would go past the screen , thats why I need a fixed size. So in this case they don't make life easier :( .
That is fine.
In this case the control will display the scroll bar and the user will scroll to the items (s)he needs.

So you don't need to hardcode anything - use sizers with wxDefaultPosition/wxDefaultSize.
Let the library decide the appropriate size and if something will not fit - the scroll bar will be shown.

In your case - the best size for the wxCheckListBox I thinkl is the same as with the wxListBox - 10 items high and maximum string width.

Keep in mind though that if you have other controls on the right of wxCLB, the width of it will be decreased to accommodate the other controls.

If you for some unknown reason (I still would like to know what this reason is) wants a different BEST SIZE you create a child of the control and override the DoGetBestSize() virtual function.
ibrahim wrote: Wed May 25, 2022 2:45 pm If your saying its possible to change the width and height of a widget without hardcoding the sizes , why don't you tell me how ??

Also Is setting the SetMaxSize() count as hardcoding , doublemax told me to use it to decrease the widgets size.
I'm using SetMinSize() to increase the widgets size ( Opposite of SetMaxSize() ) .

Also have you read my post where I mention "wxGenericSize" , where the size passed in corresponds to the same size of every platform.
Can you explain what" wxGenericSize" is? I never heard of it before..
ibrahim wrote: Wed May 25, 2022 2:45 pm I'm not hardcoding any position , I'm letting the wxFlexGridSizer take care of that for me

Is using SetMaxSize() hardcoding ?? Is using SetMinSize() hardcoding ?? if yes then how do I change the size using those functions.
However, I strongly advise you not to do that. It is portable, but the default sizes are reasonable and fit 99.999999999% of the applications (see my question above).

And yes - using SetXXXSize() is considered hardcoding as you are using static numbers for the parameters.

And you shouldn't play with setting size at all. Just let the sizers do their job - they are good at it.

Now, since you are not familiar with the sizers - why don't you try to get wxGlade, wxCrafter or wxFormBuilder and p[lay with the RAD tool.

Try to create a layout, generate a code and see what it produce.

I guarantee you will not be needing it after couple of tries...

Thank you.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ONEEYEMAN »

Hi,
ibrahim wrote: Wed May 25, 2022 3:49 pm Okay , I've changed the wxCheckListBox to only limit the height that and It works , Thanks for all the help, ONEYEEMAN made me think all of this sizer stuff was for nothing :( . I'll try to solve the third question myself :D
My question is - why do you want to liomit the height of wxCLB?
Is 10 items not enough? Or is it too much?

Remember - if the size is not fit in the screen, scroll bar will appear.

And if you are really, really, really need to display 5 items by default in the wxCLB - use the way
I explained in my previous reply.
ibrahim wrote: Wed May 25, 2022 3:49 pm Edit :


I've solved the third question myself , thanks for helping me , I'll accept your latest post as the answer :D

Edit 2 :

For some reason , on high dpi the font is smaller , all the sizes are correct , but the font is smaller.
For the font issue - are you using 3.1.5 or 3.1.6?
And which control is experiencing the issue?

Thank you.
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ibrahim »

I am using wxWidgets 3.1.6 and the font problem is with the wxStaticText

I don't know how many items could appear in the checklistbox. My application has an extension support , so if the user gets an extension then the number of items in the wxCheckListBox would change. By default 10 items appear in the wxCheckListBox , I've only done 6 items so far
Last edited by ibrahim on Wed May 25, 2022 5:07 pm, edited 1 time in total.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ONEEYEMAN »

Hi,
You are using DPI aware v2 in the manifest?
Do you see the same when you build, i.e. widgets sample?
What resolution is your monitor set on?

Thank yuo.
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ibrahim »

You are using DPI aware v2 in the manifest?
What manifest ? I am getting high dpi under Visual Studio by going to

Propeties -> Configuration Propeties -> Manifest Tool -> Input and Output -> DPI awarness
Do you see the same when you build, i.e. widgets sample?
I haven't checked
What resolution is your monitor set on?
1080p resolution



wxGenericSize isn't a thing , I just said could that be added to wxWidgets 3.2.0

Edit :

Hey ONEEYEMAN, I tried to remove the "SetMinSize()" for the wxCheckListBox and it actually does display a scroll bar. The only problem is that is displays the scroll bar after I add a LOT of items , how do I limit the number of items before it displays a scroll bar.

Better yet , can I choose how big I want my wxCheckListBox to be, based on the number of items I want there to be ?? and if the number of items in the checkbox exceeds the number I chose for the wxCheckListBox , it would automatically display a scroll bar ???

I only get to know whats going in the checklistbox until runtime
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ONEEYEMAN »

Hi,
ibrahim wrote: Wed May 25, 2022 5:12 pm
You are using DPI aware v2 in the manifest?
What manifest ? I am getting high dpi under Visual Studio by going to

Propeties -> Configuration Propeties -> Manifest Tool -> Input and Output -> DPI awarness
Yes, good.
ibrahim wrote: Wed May 25, 2022 5:12 pm
Do you see the same when you build, i.e. widgets sample?
I haven't checked
Well, you should. ;-)
ibrahim wrote: Wed May 25, 2022 5:12 pm
What resolution is your monitor set on?
1080p resolution
My question was actually incorect, sorry.
Is you monitor set for 100, 150 or 200 DPI?
ibrahim wrote: Wed May 25, 2022 5:12 pm wxGenericSize isn't a thing , I just said could that be added to wxWidgets 3.2.0
As you probably already know from the DM sample, it is called wxDefaultSize.
ibrahim wrote: Wed May 25, 2022 5:12 pm Edit :

Hey ONEEYEMAN, I tried to remove the "SetMinSize()" for the wxCheckListBox and it actually does display a scroll bar. The only problem is that is displays the scroll bar after I add a LOT of items , how do I limit the number of items before it displays a scroll bar.
OK, you need to give me an exact scenario here.
I understand you are an ESL person - I'm the same,
But you need to understand - Software Development is like math. You should be as precise as possible.

Now, if I understand you correctly, what you are looking for is:
1. Start the dialog wxCLB is empty. The control height should have enough height to accommodate X number of items.
2. You user adds some Y items to the control. The control is not resized.
3. Your user adds Z number of items to the control. The control is not resized, instead the scroll bar appears.
4. The control still have X number of items displayed.

Did I explained your scenario correctly?
And you are looking for a way to set the X?

If that is true - use the technique I already told you about: subclass the control and override its DoGetBestSize() function.
You can actually open the code for this control and grab its own DoGetBestSize() implementation, modify it and place it in
your subclass,

If that's not the scenario/problem you are looking for - please explain/correct.
ibrahim wrote: Wed May 25, 2022 5:12 pm Better yet , can I choose how big I want my wxCheckListBox to be, based on the number of items I want there to be ?? and if the number of items in the checkbox exceeds the number I chose for the wxCheckListBox , it would automatically display a scroll bar ???

I only get to know whats going in the checklistbox until runtime
You mean the content of the control is known only DURING run-time?

Now, I think that for wxCLB the parameters are as follows:
For an empty control the height is big enough to accommodate 3 items. For the one filled up, scroll bar appears after 11 item is added.
Now, those numbers aer the default for wxListBox/wxListCtrl. But I think they are applicable for the wxCLB as well.
It is pretty reasonable.

Thank you.
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Using wxSizers on high dpi, positions the widgets differently then on low dpi

Post by ibrahim »

I was reading the docs , and its saying that its more preferable to override DoGetBestClientSize() , I don't know so i'm gonna override DoGetBestSize()
I guess I can just do that
Last edited by ibrahim on Thu May 26, 2022 8:56 am, edited 1 time in total.
Post Reply