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.
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
MyImageFrameclass 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
wxWindowthat has a similar constructor, paint handler and duplicates the methods ofwxStaticBitmapthat you use in your code. Maybe simply one method to set a new bitmap and resize the control to the new bitmap dimensions.