[Python] Setting Background/Border of pyqtgraph.Scalebar

Discussão em 'Python' iniciado por Stack, Novembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to change the background/border color of a pyqtgraph.ScaleBar, because I would like it to have a black border with a white, non-transparent background. The main aim is to achieve a scalebar that, when positioned above some data, is fully visible, instead of overlapping with data (in an pyqtgraph.ImageItem, for instance).

    Here is quick minimal example to create a ScaleBar in the pyqtgraph framework:

    import pyqtgraph as pg

    app = pg.mkQApp()

    plot = pg.PlotWidget()

    scale_bar = pg.ScaleBar(size=1, width=5, offset=(-10, -20))
    scale_bar.setParentItem(plot.getPlotItem().getViewBox())

    plot.show()

    app.exec()


    and here is the documentation:

    https://pyqtgraph.readthedocs.io/en...raphicsItems/scalebar.html#pyqtgraph.ScaleBar

    ScaleBar is supposed to inherit from pyqtgraph.GraphicsObject, which itself inherits from QGraphicsObject and pyqtgraph.GraphicsItem (which is an object).

    I tried targetting the ViewBox and the ViewWidget of the scale_bar and setting their respective colors, but that didn't change anything about the appearance of the window that is created when executing the script.

    Subclassing ScaleBar to reimplement the paint method also doesn't change the color.

    Continue reading...

Compartilhe esta Página