【问题标题】:WxPython: How to get the range of displayed cells in a wx grid?WxPython:如何获取 wx 网格中显示单元格的范围?
【发布时间】:2014-04-09 17:26:32
【问题描述】:

我正在尝试获取网格上可见行/列的范围。网格可以滚动,我想要屏幕上显示的第一行和最后显示的行。如果该函数可以对列执行相同的操作,那将是一个加号。

现在我想出了这个解决方案:

def GetVisibleRowsRange(self):
    """
    return the row number of the first and last visible rows
    """
    r = 0;
    max = self.GetNumberRows()
    while r < max and not self.IsVisible(row=r, col=0, wholeCellVisible=False):
        r += 1
    firstRow = r    
    while r < max and self.IsVisible(row=r, col=0, wholeCellVisible=False):
        r += 1
    lastRow = r
    return firstRow, lastRow

这仅在第一列可见时才有效。

我想知道是否可以通过使用 windows 虚拟大小函数直接获取可见行/列的范围?

【问题讨论】:

    标签: grid wxpython wxwidgets


    【解决方案1】:

    我正在使用 wxPerl,以下 python 代码未经测试。 此方法有效,但您可能需要“get a little creative using unbound methods”。

    ux, uy = self.GetScrollPixelsPerUnit()
    sx, sy = self.GetViewStart()
    w, h = self.GetGridWindow().GetClientSize().Get()
    sx *= ux ; sy *= uy
    
    x0 = self.XToCol(sx)
    y0 = self.YToRow(sy)
    x1 = self.XToCol(sx + w, True)
    y1 = self.YToRow(sy + h, True)
    

    【讨论】:

    • 感谢 Sam,它的工作效率更高。我在最后 2 次调用中添加了 True 作为 'clipToMinMax' 参数以使其工作。
    猜你喜欢
    • 1970-01-01
    • 2017-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 2018-01-08
    • 2017-02-03
    相关资源
    最近更新 更多