Overlay item background color

64 views
Skip to first unread message

Toni

unread,
Jul 25, 2017, 8:33:53 AM7/25/17
to pyqtgraph
Hi everyone.

I have a question to ask about PlotItem and its background customization.

My current situation is:
- I have an ImageItem that shows a stream of images
- An overlayed PlotItem with some stats
- An overlayed TextItem with some stats too

What I would like to do is add a sort of opaque background to the PlotItem and the TextItem to make the graph axes and the writings more readable, something like half transparent white background.

Is it possible?

Here is a little snippet of my current code in the __init__ method, maybe it could help

        QtCore.QObject.__init__(self)
        
        app = QtGui.QApplication([])
        
        # Create window with GraphicsView widget
        win = pg.GraphicsLayoutWidget()
        win.show()  ## show widget alone in its own window
        win.setWindowTitle('Realtime prediction')

                 # Create ViewBox
        self.view = win.addViewBox(enableMouse=False)
        self.view.invertY()
        self.view.setAspectLocked(True)
        
        # Create image item
        self.vis = pg.ImageItem()
        self.view.addItem(self.vis)
        
        # Create obstacle histogram
        plot = pg.PlotItem() # <- background here
        plot.layout.setMinimumWidth(200.0)
        plot.layout.setMinimumHeight(150.0)      
        axesB = plot.getAxis('bottom')
        axesB.setTicks([xdict.items()])
        axesB.setPen((0, 0, 0))
        axesL = plot.getAxis('left')
        axesL.setPen((0, 0, 0))
        plot.setZValue(10)
        plot.setY(320.0)
        plot.setX(220.0)
        self.view.addItem(plot)
        
        self.barGraphItem = pg.BarGraphItem(x = x, height = self.y, width = 1, brush = (255, 0, 0, 128))
        plot.addItem(self.barGraphItem)
        
        self.text = pg.TextItem('Loading...') # <- background here
        self.text.setColor((0.5, 0.5, 0.5))
        self.view.addItem(self.text)

        QtGui.QApplication.instance().exec_()


Thank you in advance for the answers.

Toni.
Reply all
Reply to author
Forward
0 new messages