【问题标题】:How can I show a bitmap in wxGrid header cell?如何在 wxGrid 标题单元格中显示位图?
【发布时间】:2014-06-23 07:27:41
【问题描述】:

使用 wxPython 我只想在wxGrid 的左上网格角单元格中呈现位图,但不知道如何执行此操作。

我得到了左上网格角单元格的窗口对象

mywindow = self.someGrid.GetGridCornerLabelWindow()

但现在我无法为这些 Window-Object 设置位图。有人可以帮帮我吗?

【问题讨论】:

    标签: grid wxpython


    【解决方案1】:

    您需要创建一个GridLabelRendererwxPython 演示 中有一个示例,其中包含以下代码:

    class MyCornerLabelRenderer(glr.GridLabelRenderer):
        def __init__(self):
            import images
            self._bmp = images.Smiles.getBitmap()
    
        def Draw(self, grid, dc, rect, rc):
            x = rect.left + (rect.width - self._bmp.GetWidth()) / 2
            y = rect.top + (rect.height - self._bmp.GetHeight()) / 2
            dc.DrawBitmap(self._bmp, x, y, True)
    

    要使用此渲染器,您必须执行以下操作:

    g = MyGrid(self, size=(100,100))
    g.SetColLabelRenderer(0, MyCornerLabelRenderer())
    

    这会将图像放入第一列。

    【讨论】:

    • 非常感谢您的回答。我认为这将起作用,但仅适用于 python 3.x 版本(通过阅读示例)。但是对于这个项目,我必须使用 Python 2.5...
    • 根据wxpython.org/recentchanges.php,在 wxPython 2.9.0.1 中添加了 GridLabelRenderer。这里似乎有一个支持 Python 2.5 的 2.9 版本:sourceforge.net/projects/wxpython/files/wxPython/2.9.1.1
    • 感谢您的帮助,问题是:这个项目是为一家所有人都从一个管理部门获取他们的软件的公司而设计的,因此向所有 PC 推出更新版本的 wxpython 并不容易。 S 我正在使用 wx-Version 2.8 ... :(
    • 你应该看看GridLabelRenderer是如何实现的。也许你可以用它来滚动你自己的。我怀疑您需要使用设备上下文在某个位置进行绘制,但我真的不知道。
    猜你喜欢
    • 1970-01-01
    • 2018-12-17
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多