What is the correct way to get wxPanel visible size?

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
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

What is the correct way to get wxPanel visible size?

Post by Tapsa »

I have two wxPanels, whose visible width and height I need to get, but both GetSize() and GetClientSize() return false sizes.
GetSize() from wxBufferedPaintDC also returns false size. I want to center my wxBitmap to the wxPanel, but without real sizes that's impossible.
I have not made any scaling for these wxPanels yet. GetClippingBox() also does not work, returns impossible sizes for the visible area size.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: What is the correct way to get wxPanel visible size?

Post by doublemax »

I have two wxPanels, whose visible width and height I need to get, but both GetSize() and GetClientSize() return false sizes.
That's almost impossible. The only reason i could think of is that you connected the paint event handler to a method of the parent frame incorrectly and get the size of the parent frame instead.

Can you show some code?
Use the source, Luke!
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: What is the correct way to get wxPanel visible size?

Post by Tapsa »

I do connect the paint event to wxFrame using this:

Code: Select all

Graphics_SLP_Image->Connect(Graphics_SLP_Image->GetId(), wxEVT_PAINT, wxPaintEventHandler(AGE_Frame::OnDrawGraphicSLP), NULL, this);
"this" is the wxFrame.
User avatar
T-Rex
Moderator
Moderator
Posts: 1249
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Re: What is the correct way to get wxPanel visible size?

Post by T-Rex »

As far as I understand, you can try to get wxClientDC and it's size when you want, not only in wxEVT_PAINT handler. So, possibly, the wxClientDC's getSize() should do what you want.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: What is the correct way to get wxPanel visible size?

Post by doublemax »

Code: Select all

Graphics_SLP_Image->Connect(Graphics_SLP_Image->GetId(), wxEVT_PAINT, wxPaintEventHandler(AGE_Frame::OnDrawGraphicSLP), NULL, this);
This is correct, but then GetSize() and GetClientSize() in the paint event handler will return the values for the frame. Use Graphics_SLP_Image->GetClientSize() instead.

This kind of code is cleaner if you keep the paint event handler in the panel class.
Use the source, Luke!
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: What is the correct way to get wxPanel visible size?

Post by Tapsa »

I'm sorry to say, but I tried your suggestions before I came here to ask this. I think there is something else broken. wxWidgets basically allows my GUI code to result in broken behavior, without telling me where the error is.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: What is the correct way to get wxPanel visible size?

Post by PB »

If you want to get help you need to provide necessary information, as usual starting with wxWidgets version and the platform used. Then provide the minimum compilable example to demonstrate the issue. It could also be useful not just saying "false sizes" but to provide hard numbers for expected and returned sizes, so people may have a better idea about what is going on.
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: What is the correct way to get wxPanel visible size?

Post by Tapsa »

It's okay. Instead of taking 1 hour to make minimal sample, I will move my graphics view to separate window, which seems better for my use.

If you want to fix wxWidgets issues you should compile my program and even try to port it to wxWidgets 3.0.2 from 2.8.12. There are so many issues (when upgrading to 3) it would take days to make minimal samples for all of them.
https://github.com/Tapsa/AGE

In this particular case my wxPanel has size around 300 x 300 pixels, but it returns size that is 3 to 4 times larger than that. This must also be the reason why wxWrapSizer fails to work in my wxScrolledWindow (size around 700 x 600).
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: What is the correct way to get wxPanel visible size?

Post by PB »

Tapsa wrote:It's okay. Instead of taking 1 hour to make minimal sample, I will move my graphics view to separate window, which seems better for my use.
Sorry, to create a truly useful minimal example of the issue described in the OP should take just a few minutes and nobody is going to do that for you.
Tapsa wrote:If you want to fix wxWidgets issues you should compile my program and even try to port it to wxWidgets 3.0.2 from 2.8.12. There are so many issues (when upgrading to 3) it would take days to make minimal samples for all of them.
I'm afraid you are under wrong impression here. Firstly, you should prove the issue is within wxWidgets using approach described above. Secondly, wxWidgets is a community project rather dependent on submissions from people using it, who do it for free. Lastly, if you want someone to port your application and fix the tons of bugs you admit it has, you will have to pay them or find something else to motivate them..
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: What is the correct way to get wxPanel visible size?

Post by Tapsa »

Which is why we can let this case rest in peace. I can not do a minimal sample of this within minutes.
Obviously it is not necessarily an error withing wxWidgets, but rather I have been using wxWidgets in a way that was never meant to be.
Post Reply