grid - 在 wx.grid wxpython 中用鼠标悬停在单元格上时的工具提示消息

标签 grid wxpython tooltip mousehover

我有一个 wx.grid 表,我想在将鼠标悬停在一个单元格上时设置一个工具提示,我尝试了下面 Mike Driscoll 的建议,它有效,但我不能再用鼠标拖动选择多个单元格,它只允许我选择最多 1 个单元格,请帮助:

self.grid_area.GetGridWindow().Bind(wx.EVT_MOTION, self.onMouseOver)

    def onMouseOver(self, event):
        '''
        Method to calculate where the mouse is pointing and
        then set the tooltip dynamically.
        '''

        # Use CalcUnscrolledPosition() to get the mouse position
        # within the
        # entire grid including what's offscreen
        x, y = self.grid_area.CalcUnscrolledPosition(event.GetX(),event.GetY())

        coords = self.grid_area.XYToCell(x, y)
        # you only need these if you need the value in the cell
        row = coords[0]
        col = coords[1]
        if self.grid_area.GetCellValue(row, col):
            if self.grid_area.GetCellValue(row, col) == "ABC":
                event.GetEventObject().SetToolTipString("Code is abc")
            elif self.grid_area.GetCellValue(row, col) == "XYZ":
                event.GetEventObject().SetToolTipString("code is xyz")
            else:
                event.GetEventObject().SetToolTipString("Unknown code")   

最佳答案

好的,我找到了解决方案,我必须跳过该事件:

def onMouseOver(self, event):
        '''
        Method to calculate where the mouse is pointing and
        then set the tooltip dynamically.
        '''

        # Use CalcUnscrolledPosition() to get the mouse position
        # within the
        # entire grid including what's offscreen
        x, y = self.grid_area.CalcUnscrolledPosition(event.GetX(),event.GetY())

        coords = self.grid_area.XYToCell(x, y)
        # you only need these if you need the value in the cell
        row = coords[0]
        col = coords[1]
        if self.grid_area.GetCellValue(row, col):
            if self.grid_area.GetCellValue(row, col) == "ABC":
                event.GetEventObject().SetToolTipString("Code is abc")
            elif self.grid_area.GetCellValue(row, col) == "XYZ":
                event.GetEventObject().SetToolTipString("code is xyz")
            else:
                event.GetEventObject().SetToolTipString("Unknown code")   
        event.Skip()

谢谢
此致

关于grid - 在 wx.grid wxpython 中用鼠标悬停在单元格上时的工具提示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20589686/

相关文章:

html - 响应式网格系统中的列

python - wxpython 对话框返回值,带有销毁选项

python - 在wxpython listctrl中创建删除线

javascript - 如何将 Twitter Bootstrap 工具提示应用于 <span> 中包含的文本?

java - 如何在 Eclipse 中从 Java 编辑器显示 scala 文档?

html - 获取响应式三列网格以在特定断点处堆叠为两列

wpf - 在WPF中,如何确定控件在网格中的列/行?

python - 如何用wxpython设置相对位置?

WPF:工具提示放置在触摸屏上的行为不同

css 网格自定义布局流程