Hi All,
I have a question for the best way to deal with a problem, or perhaps whether the problem I’m finding is a bug.
I’ve been trying to make my wxpython app be cross-platform, and The Flicker Problem with Windows is considerable. The advice on solving it seems to indicate that one should do the following:
self.SetBackgroundStyle(wx.BG_STYLE_PAINT)
``
My app draws to the whole window (it’s a graphical application) so that’s actually no problem for me.
Except for one place: the corner between the horizontal and vertical scrollbars.
It’s not part of the Client Area, so I’m never drawing to it. But if I change the size of my virtual area, so that before I have one scrollbar and afterwards I have two scrollbars, then I can get a chopped off part of a scrollbar leftover in the corner. My app zooms in and out of an image, so I do change the virtual area.
My question: Is there a best practice to avoid this situation when you’re not auto-erasing the background? I see it in macOS (see images below) and also in Windows.
thanks!
Matt
Sample code which displays the behavior:
#!/usr/bin/env python3
import wx
class MyCanvas(wx.ScrolledCanvas):
def init(self, parent, id=wx.ID_ANY):
super().init(parent, id)
# attempting to avoid Windows flicker
# THIS IS WHAT CAUSES THE SCROLLBAR ARTIFACT
# if this line is absent, scrollbar corner is erased fine
self.SetBackgroundStyle(wx.BG_STYLE_PAINT)
# x smaller than MainWindow, y larger than MainWindow
self.SetVirtualSize(600, 1000)
self.SetScrollRate(10,10)
# scroll so vert. scrollbar is at bottom
self.Scroll(0, 2000)
wx.CallLater(
1000,
self.zoom_scroll,
)
def zoom_scroll(self):
# x larger than MainWindow, y larger than MainWindow
self.SetVirtualSize(1000, 1200)
# scroll so vert. scrollbar is at bottom
self.Scroll(0, 2000)
class MainWindow(wx.Frame):
def init(self, *args, **kwargs):
super().init(*args, **kwargs)
self.my_canvas = MyCanvas(self)
self.SetSize((800, 600))
self.Show(True)
def main():
my_app = wx.App()
main_win = MainWindow(None)
my_app.MainLoop()
if name == ‘main’:
main()
``
before enlargement of Virtual Area:
after enlargement of Virtual Area: