如何构造简单的wxWidgets图像显示
我编写了一个 wxPython 程序,并将其转换为 wxWidgets。该程序有一个显示图像的滚动窗口。继 Rappin,wxPython 实际操作(清单 12.1)之后,我在面板中使用了 StaticBitmap。在浏览最新的 wxWidgets 文档时,我发现了一个 可怕的警告,wxStaticBitmap 应该只用于非常小的图像。它说:“...如果您想便携式显示更大的图像,您应该使用自己的控件。”好的。给我看看。我没有“自己的控制权”。
是拉平错了,还是文档已经过时了?
毫无疑问,对于新手来说,问题是在 wxWidgets 中创建一个简单的图像视图窗口的正确方法是什么? wxStaticBitmap 的直接替代品会很好。我查看了 wxWidgets“samples”目录中的“image”程序。它就像战争与和平那么长。当然,一定有一个罐装课程或一个简单的食谱。
I wrote a wxPython program that I am translating to wxWidgets. The program has a scrolled window that displays an image. Following Rappin, wxPython In Action (Listing 12.1), I used a StaticBitmap within a panel. While surfing the latest wxWidgets documentation, I found a dire warning that wxStaticBitmap should only be used for very small images. It says, "... you should use your own control if you want to display larger images portably." Okay. Show me. I don't have my "own control."
Was Rappin wrong, or is the documentation out of date?
The question - a newbie one, no doubt - is what is the right way to do a simple image-view window in wxWidgets? A drop-in replacement for wxStaticBitmap would be nice. I looked into the "image" program in the wxWidgets "samples" directory. It's as long a War and Peace. Surely there must be a canned class or a simple recipe.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要让“图像”样本的大小欺骗了您,只需几行代码即可完成您想要的操作。
在image.cpp文件中搜索
MyImageFrame
类,它无非是一个带有私有位图字段的类,一个用于设置位图和窗口客户端的自定义构造函数大小,以及EVT_PAINT
的事件处理程序:由于您不需要框架类,因此这里是您的方法:您创建一个
wxWindow
的简单后代,它具有类似的构造函数、paint处理程序并复制您在代码中使用的wxStaticBitmap
方法。也许只是一种设置新位图并将控件大小调整为新位图尺寸的方法。Don't let the size of the "image" sample fool you, only a few lines of code are necessary to do what you want.
Search for the
MyImageFrame
class in the image.cpp file, it is nothing more than a class with a private bitmap field, a custom constructor to set the bitmap and the window client size, and an event handler forEVT_PAINT
:Since you don't want a frame class here's your recipe: You create a simple descendant of
wxWindow
that has a similar constructor, paint handler and duplicates the methods ofwxStaticBitmap
that you use in your code. Maybe simply one method to set a new bitmap and resize the control to the new bitmap dimensions.