how to remove border of graphicsLayoutWidget

376 views
Skip to first unread message

julien....@polytechnique.edu

unread,
Dec 6, 2018, 10:08:34 AM12/6/18
to pyqtgraph
Hi
I use a  graphicsLayoutWidget to plot an image from a camera. But i want to remove the 2 black border around and to full fill the widget.
Does somebody know how to do it? 

My program is :

self.winImage = pg.GraphicsLayoutWidget(border=(100,100,1))
        self.winImage.setAspectLocked(True)
        self.winImage.setContentsMargins(1,1,1,1)
        vbox2=QVBoxLayout()
        vbox2.addWidget(self.winImage)
        vbox2.setContentsMargins(0,0,0,0)
        self.p1=self.winImage.addPlot()
        self.imh=pg.ImageItem(border='w')
        self.p1.addItem(self.imh)
        self.p1.setMouseEnabled(x=False,y=False)
        self.p1.setContentsMargins(1,1,1,1)
        self.p1.setAspectLocked(True,ratio=1)
        self.p1.setContentsMargins(0,0,0,0)

hMainLayout=QHBoxLayout()
        hMainLayout.addLayout(vbox2)
        hMainLayout.addLayout(vbox1)
        hMainLayout.setContentsMargins(0,0,0,0)
        hMainLayout.setStretch(2,1)
        
        self.setLayout(hMainLayout)
        self.setContentsMargins(1,1,1,1)
Capture d’écran 2018-12-06 à 16.00.22.png

Patrick

unread,
Dec 6, 2018, 10:04:00 PM12/6/18
to pyqtgraph
Hi,

There's two sets of "borders" I think you're talking about. Outside the yellow box and inside.
For outside, this is the contents margin of the GraphicsLayout -- but you'll need to get the reference to that from the central item in the GraphicsLayoutWidget:

self.winImage.ci.setContentsMargins(0, 0, 0, 0)

For inside the yellow box, this is about the extent of the ViewBox (essentially the plot limits). Set them manually eg:

self.p1.setLimits(xMin=0, 100, yMin=0, yMax=100)

So an example would be:

#!/usr/bin/env python3

import numpy as np
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QVBoxLayout, QHBoxLayout
import pyqtgraph as pg

class TestImage(QtWidgets.QMainWindow):

   
def __init__(self):
       
super().__init__()

       
# Create empty data structure
       
self.data = np.random.rand(100, 100)

       
self.winImage = pg.GraphicsLayoutWidget()
       
self.winImage.ci.setContentsMargins(0, 0, 0, 0)
       
self.p1 = self.winImage.addPlot()
       
self.imh = pg.ImageItem(self.data)
       
self.p1.addItem(self.imh)
       
self.p1.setMouseEnabled(x=False,y=False)

       
self.p1.hideAxis('left')
       
self.p1.hideAxis('bottom')
       
self.p1.hideButtons()

       
self.p1.scale(1.0, 1.0)
       
self.p1.setLimits(xMin=0, xMax=self.data.shape[0], yMin=0, yMax=self.data.shape[1])
       
       
self.setCentralWidget(self.winImage)

def main():
   
import sys
    app
= QtWidgets.QApplication(sys.argv)
    mainwindow
= TestImage()
    mainwindow
.show()
    sys
.exit(app.exec_())

if __name__ == '__main__':
    main
()


Patrick

julien....@polytechnique.edu

unread,
Dec 7, 2018, 4:05:37 AM12/7/18
to pyqtgraph
Hi
It 's perfect
Thanks a lot
Reply all
Reply to author
Forward
0 new messages