wxwidgets/wxPython:在保持纵横比的同时调整 wxFrame 的大小
我有一个只有一个孩子的 wx.Frame 。 在设置子项的 wx.Sizer 时,我可以使用 wx.SHAPED 标志,它可以保持子项的纵横比锁定。 然而,框架在其纵横比方面仍然具有完全的自由度,并且会在孩子未使用的区域中留下空白区域。
如何在调整大小时锁定 wx.Frame 的纵横比?
I have a wx.Frame that has only a single child. While setting up the child's wx.Sizer, I can use the wx.SHAPED flag, which keeps the aspect ratio of the child locked. However, the Frame still has complete freedom in it's aspect ratio, and will leave a blank space in the area that is left unused by the child.
How can I lock the aspect ratio of the wx.Frame during resizing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大小调整器不能应用于顶级窗口(为了定义窗口本身的属性而不是其内容),因此不幸的是没有“真正”的方法来锁定宽高比。 最好的选择是捕获窗口的
OnSize
事件,获取用户想要的窗口大小(存储在wxSizeEvent
中),计算新的宽度根据宽高比和高度,然后立即使用新尺寸调用SetSize
。这种技术的缺点是在调整大小时会出现视觉伪影(操作系统最初会根据用户拖动窗口的方式绘制窗口,但在调用
SetSize
后立即重新绘制它,从而导致闪烁效果)所以这不是一个很好的解决方案,但是由于您无法将顶级窗口锁定为宽高比(并且根本不需要使用SetSize
调整大小),因此您必须决定闪烁是否是值得。Sizers cannot be applied to top-level windows (in order to define properties of the windows themselves as opposed to their contents), so unfortunately there is no "true" way to lock in the aspect ratio. Your best bet would be to catch your window's
OnSize
event, get the size that the user wants the window to be (which is stored in thewxSizeEvent
), calculate the new width and height according to the aspect ratio and then immediately callSetSize
with the new size.This technique has the drawback of visual artifacts during resizing (the operating system will initially paint the window according to how the user has dragged it but then immediately redraw it after you call
SetSize
, leading to a flickering effect) so it isn't a great solution, however since you cannot lock top-level windows into aspect ratios (and prevent the need to resize withSetSize
at all) you'll have to decide whether the flickering is worth it.这是一些示例代码。 有一点闪烁,我不确定有什么好方法可以消除它。
Here is some sample code. There is a good bit of flicker, and I'm not sure of a good way to eliminate it.