【问题标题】:Tooltip message when hovering on cell with mouse in wx.grid wxpython在 wx.grid wxpython 中使用鼠标悬停在单元格上时的工具提示消息
【发布时间】:2014-01-02 14:10:06
【问题描述】:

我有一个 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")   

【问题讨论】:

    标签: grid wxpython tooltip mousehover


    【解决方案1】:

    好的,我找到了解决方案,我要跳过这个事件:

    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()
    

    谢谢 最好的问候

    【讨论】:

    • 如果有人能评论原因就太好了:出了什么问题,如何解决?
    【解决方案2】:

    @GreenAsJade 由于声誉问题,我无法发表评论,因此我在这里回答您的问题!

    为什么:出了什么问题,如何解决?

    如果您检查事件 Hanlder 和 @alwbtc 的事件处理程序之间的区别,唯一的区别是 event.Skip()

    只要 wx.EVT_xx 与代码中的自定义方法绑定,wxpython 就会覆盖默认定义。因此,事件处理以 onMouseOver 结束。 event.Skip() 会将事件传播到 wxptyhon 的 _core 允许它执行默认事件处理程序。

    希望这能回答你的问题!

    【讨论】:

      猜你喜欢
      • 2019-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 2014-12-31
      • 2015-05-11
      • 1970-01-01
      相关资源
      最近更新 更多