简体   繁体   中英

Get mouse position in sizer? wxpython

that it is possible to get the mouse position in wxpython using

event.GetPosition()

however, is it possible to get the position of a mouse in a sizer? Would this work even in an expanding sizer?

Thanks.

The X,Y position in a sizer is exactly the same as the window that the sizer belongs to, assuming that the sizer is the sizer assigned to that window. If you've got nested sizers then you can use sizer.GetPosition and sizer.GetSize to figure out if the position is inside that nested sizer.

However I would guess that the knowing the mouse position within the sizer is not going to be very useful. You are probably wanting to know which item within the sizer that the mouse position is over, like a HitTest type of method. You can implement something like that using the sizer.GetChildren() method and iterate over its items (they are wx.SizerItem objects) and look at the item's position and size to find the one that has the point within it. If the item is a sizer then you can recursively descend to that sizer and do the same thing until you find the leaf item at the desired point.

Sizers don't work with absolute positioning. They're for relative positioning. Sizers are the best at making your layout look right across multiple platforms and themes. If you really want to be able to insert stuff at specific xy coordinates, then don't use a sizer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM