简体   繁体   English

获取鼠标在sizer中的位置? wxPython的

[英]Get mouse position in sizer? wxpython

that it is possible to get the mouse position in wxpython using 可以使用以下命令在wxpython中获取鼠标位置

event.GetPosition() 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. 假设sizer是分配给该窗口的sizer,则sizer中X,Y的位置与sizer所属的窗口完全相同。 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. 如果您有嵌套的sizer,则可以使用sizer.GetPosition和sizer.GetSize来确定位置是否在嵌套的sizer中。

However I would guess that the knowing the mouse position within the sizer is not going to be very useful. 但是我猜想知道sizer中的鼠标位置不会非常有用。 You are probably wanting to know which item within the sizer that the mouse position is over, like a HitTest type of method. 您可能想知道鼠标位置在sizer中的哪个项目上,就像HitTest类型的方法一样。 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. 你可以使用sizer.GetChildren()方法实现类似的东西并迭代它的项目(它们是wx.SizerItem对象)并查看项目的位置和大小以找到其中有一个点的那个。 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. Sizer最适合在多个平台和主题上展示您的布局。 If you really want to be able to insert stuff at specific xy coordinates, then don't use a sizer. 如果您真的希望能够在特定的xy坐标处插入内容,那么请不要使用sizer。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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