20 x 20 wx.Control bug/glitch.. or MSW quirk?

I came across this oddity when sub-classing a wx.Control

If I set the size to 20 x 20, the ClientSize and VirtualSize calculated out to be 16 x 16?!?
Setting the control to any other dimension calculates as expected, matching the set size.

I only noticed it when drawing the control in a FlexSizer and saw the strange border/placement anomaly.
The 20 x 20 draws correctly in other sizers that I have tested, even though the ClientSize and VirtualSize still come out as 16 x 16

Is this a MS Windows quirk or an issue with wx?

demo4_.py (7.8 KB)

Well you are doing a lot of things in your code…
Now, as far as I can see, this toy model works fine:

import wx

class BareBones(wx.Control): 
    def __init__(self, *a, **k):
        wx.Control.__init__(self, *a, **k)

class MainFrame(wx.Frame):
    def __init__(self, *a, **k):
        wx.Frame.__init__(self, *a, **k)
        p = wx.Panel(self)
        self.c1 = BareBones(p, size=(15, 15))
        self.c2 = BareBones(p, size=(20, 20))
        self.c3 = BareBones(p, size=(25, 25))
        b = wx.Button(p, -1, 'info')
        b.Bind(wx.EVT_BUTTON, self.onclic)
        s = wx.GridSizer(1, 4, 0, 0) # or BoxSizer, or FlexGridSizer...

    def onclic(self, e):
        for ctl in self.c1, self.c2, self.c3:
            print(ctl.GetSize(), ctl.GetBestSize(), ctl.GetClientSize())

app = wx.App()

If it works for you too, then I guess it’s a matter of slowly stripping down your code, until you hit the bit that triggers the glitch…

Hi riccardo,
thanks for having a look.

What I see is 3 boxes with a border around around them - that border is the problem
My code removes the border for every rectangle, except for the one sized at 20 x20.
I can solve the problem, and have done so in the control I’m building, but I was just interested in knowing why that 20 x 20 was different to every other size.

Picking around the internetz didn’t reveal much but I did come across a mention of some legacy with early windows doing something similar with icon sizing, but I couldn’t say it was the same issue.