1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] pyqtgraph: LegendItem offset returns false values regardless of position

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I have a Qt5 window with a pyqtgraph in a dynamic situation, i.e., plots, axes, curves can be added or modified. Also, the legend can be shown and hidden. Since the user can also drag the legend to a different place using the mouse, I would like to store its position and perhaps restore this position later. Setting a position using LegendItems' setOffset works as expected, but regardless of the actual position, LegendItems' offset attribute always returns the same values. Here's a MWE:

    import numpy as np
    import pyqtgraph as pg

    win = pg.plot()
    win.setWindowTitle('MWE legend offset')

    c1 = win.plot([np.random.randint(0,8) for i in range(10)], pen='r', name='curve1')

    legend = pg.LegendItem((80,60), offset=(70,20))
    legend.setParentItem(win.graphicsItem())
    legend.addItem(c1, 'curve1')

    print(f"Before setting an offset: {legend.offset}") # Gives (70,20)
    legend.setOffset([300,300])
    print(f"After setting an offset: {legend.offset}") # Gives (70,20) as well

    if __name__ == '__main__':
    pg.exec()


    Any idea how to get the real LegendItem position?

    Continue reading...

Compartilhe esta Página