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

 只都是孩子Whitney 发布于 2023-02-10 13:35

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

alwbtc.. 5

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

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

最诚挚的问候

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

    最诚挚的问候

    2023-02-10 13:38 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有