How to get the 'absolute' position of a widget? Topic is solved
How to get the 'absolute' position of a widget?
I use panels and boxsizers to manage the layout of my app, at the same time I want to draw a bitmap on the panels. It seems dc.drawbitmap use 'absolute' position, that is, the position relative to the whole window. Also I notice that the GetPosition function returns a position relative to the parent widget. As a result, I can't draw a bitmap relative to the panel. Is there any solution to this?
Re: How to get the 'absolute' position of a widget?
What do you mean? If you want to draw on a window, you draw on its dc with coordinates relative to the upper left corner, with window and DC coordinates generally matching each other.
If you want to draw on other windows (generally a very bad idea), you can easily convert the coordinates between parent/child/sibling windows.
If you want to draw on other windows (generally a very bad idea), you can easily convert the coordinates between parent/child/sibling windows.
Re: How to get the 'absolute' position of a widget?
Thanks for the reply. What I really want is to draw an image in a window with position relative to a certain panel in this window, rather than the window itself.PB wrote: ↑Sat Jun 05, 2021 7:23 am What do you mean? If you want to draw on a window, you draw on its dc with coordinates relative to the upper left corner, with window and DC coordinates generally matching each other.
If you want to draw on other windows (generally a very bad idea), you can easily convert the coordinates between parent/child/sibling windows.
Actually I have something like a 'image panel', I want to use it like a panel so that I could use boxsizers to manage the layout. At the same time I want to draw image in this panel, the image should be positioned strictly in the panel.
Re: How to get the 'absolute' position of a widget?
Why not draw using this panel?
If you have a wxFrame and want to draw over its child wxPanel (once again, a bad idea), I think it would conflict with the child drawing (and would generally be drawn under the child). But in theory, the DC coordinates of the parent should still match those of the child window. E.g., if the child window is at (100,100) returned by its GetPosition(), the parent DC coordinates drawing should match it?
Re: How to get the 'absolute' position of a widget?
My appology. After some experiments I found out that dc.drawbitmap use a coordinate relative to the current panel (namely, I can draw 'using this panel'). I have taken for granted that the dc use absolute position since all my early experiments are done with a single panel covering the whole window. This is indeed a stupid question to ask, lol.PB wrote: ↑Sat Jun 05, 2021 7:44 amWhy not draw using this panel?
If you have a wxFrame and want to draw over its child wxPanel (once again, a bad idea), I think it would conflict with the child drawing (and would generally be drawn under the child). But in theory, the DC coordinates of the parent should still match those of the child window. E.g., if the child window is at (100,100) returned by its GetPosition(), the parent DC coordinates drawing should match it?