在OSX上,空单元格和滚动时,ComboBox绘制不正确

2024-09-28 21:51:29 发布

您现在位置:Python中文网/ 问答频道 /正文

给定一个简单的wx.grid.Gridwx.grid.GridCellChoiceEditor作为默认单元格编辑器。现在尝试在网格中向下滚动并在空单元格上开始编辑。现在,如果单元格有值,一切都会好起来的。但是,当单元格为空时,组合框的textcrlt将绘制在错误的位置。似乎垂直滚动偏移量被减去两次。Source code for sample app。在

Rendered correctly

Rendered incorrectly

WX版本2.9.4.0


Tags: 网格编辑sourcefor错误绘制code编辑器
1条回答
网友
1楼 · 发布于 2024-09-28 21:51:29

作为一种解决方法,我现在设置一个非空值,当编辑器即将显示时。使用wx.CallAfter我再次将值设置为空,这样用户就不会注意到任何东西。但是,网格中的值将保持非空值(空格),因为在回调中更改它将触发不正确的重新呈现。在

def __init__(...):
    # ...
    self.grid1.Bind(wx.grid.EVT_GRID_EDITOR_CREATED, self.editor_created)
    self.grid1.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.editor_shown)

def editor_created(self, event):
    self.control = event.GetControl()
    event.Skip()

def editor_shown(self, event):
    cursor = event.Row, event.Col
    value = self.grid1.GetCellValue(*cursor)
    if not value:
        self.grid1.SetCellValue(cursor[0], cursor[1], ' ')
        def unfix():
            self.control.SetValue(value)
            self.control.Popup()
            # @todo should set the cell value back to empty value here,
            # but that triggers the bug again.
        wx.CallAfter(unfix)
    event.Skip()

以及工作示例的source code。在

相关问题 更多 >