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: 7459
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,
Keep the DoGetBestSize() override, if its working.

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 the entire post, i've edited it
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
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 »

Hhi,
You said that when you overrode DoGetBestSize() everything worked, right?

So, keep that code...

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 never said I overrode DoGetBestSize() ???
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 »

:evil: :evil: PLEASE READ MY ENTIRE POST :evil: :evil:
_____________________________________

Okay I managed to override DoGetBestClientSize() with my subclass of wxCheckListBox. It looks exactly the same as before :D . The Only problem is
The source code I modified for DoGetBestClientSize(), has windows specific code :

Code: Select all

// find the widest string
		int wLine;
		int wListbox = 0;
		for (unsigned int i = 0; i < m_noItems; i++)
		{
			wxString str(GetString(i));
			GetTextExtent(str, &wLine, NULL);
			if (wLine > wListbox)
				wListbox = wLine;
		}

		// give it some reasonable default value if there are no strings in the
		// list
		if (wListbox == 0)
			wListbox = 6 * GetCharWidth();

		// the listbox should be slightly larger than the widest string
		wListbox += 3 * GetCharWidth();

		// add room for the scrollbar
		wListbox += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, m_parent);



// I've made my changes from here:  



		// don't make the listbox too tall (limit height to 6 and a two quarters items) but don't
		// make it too small neither
		int hListbox = SendMessage(GetHWND(), LB_GETITEMHEIGHT, 0, 0) * wxMin(wxMax(6, 3), 6);
        
		// Get Some Additional Empty Space
		int additional_space = ((((hListbox / 6) / 3)) + ((hListbox / 6) / 9));

		// Add it to the hieght
		hListbox += additional_space;
		wxSize best = wxSize(wListbox, hListbox);




		// add room for the checkbox
		return MSWGetFullItemSize(best.x, best.y);
		
As you can see I have edited everything after that SendMessage() call.
this function SendMessage() is windows specific , what SendMessage() does it that it gets the height of a single checkbox.

This function MSWGetFullItemSize() is also windows specific , and allot of other stuff is also windows specific


Is there a cross-platform way to override DoGetBestClientSize ?
Last edited by ibrahim on Fri May 27, 2022 10:39 am, edited 1 time in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

I think you're over-complicating things. Here's what i'd do:

- set a reasonable minimum height for the wxchecklistbox, you could even use different hard-coded values for each platform
- make the sizer row that contains the wxchecklistbox growable
- make the outer window resizable
- store the size of that window when it's closed
- restore the size of that window when it's opened

That way the user can resize the dialog to the size he wants and everyone is happy.

BTW: What's the minimum/maximum number of checkboxes in that control?
Use the source, Luke!
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 could do that , but I want to go with my plan. Please answer my questions....

Edit :

I could actually have a different harcoded size per platform with some preprocessor platform macros.....

But I would rather do this , ONEEYEMAN suggested this
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 »

BTW: What's the minimum/maximum number of checkboxes in that control?
It could be anything , I only find out at runtime.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

I think the cleanest way would be to create a hidden control and measure its size at runtime.

Code: Select all

wxCheckListBox *clb = new wxCheckListBox();
clb->Hide();
clb->Create(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxArrayString() );
for(int i = 0; i < 6; i++ ) {    // change number of items you want here
    clb->Append("dummy");
}
wxSize bestSize = clb->GetBestSize();
clb->Destroy();
Use the source, Luke!
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 »

This gives me the width and height of all the checkboxes in the list right ??

I want to add to the returned size a bit more extra height , based on the size of one checkbox.
Last edited by ibrahim on Fri May 27, 2022 10:58 am, edited 1 time in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

ibrahim wrote: Fri May 27, 2022 10:57 am This gives me the width and height of all the checkboxes in the list right ??
It gives you the size of the whole control including borders etc.
Use the source, Luke!
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 edited my above post
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

The code i posted contains everything you need.
Use the source, Luke!
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 »

OMG it worked , I used your code and edited the "bestSize" to get extra space according to the height of one checkbox. Then I used "SetMinSize" on the "wxCheckListBox" like this :

Code: Select all

reports__->SetMinSize(this->FromDIP(wxSize(-1, bestSize.y)));
now Its cross-platform :D :D

I made extra space like this :
bestSize.y += ((((bestSize.y / 6) / 3) * 2) + ((bestSize.y / 12) / 2));
Its pure math :lol:



Now I don't need the subclass.

I have made the wxCheckListBox without hardcoding now :) . I only have to do the textctrls now
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

Code: Select all

reports__->SetMinSize(this->FromDIP(wxSize(-1, bestSize.y)));
I don't think you need FromDIP() here, as the size is already calculated based on a real control.
Use the source, Luke!
Post Reply