I'm trying to setup a graphics view using Pyqt. I have a vertical box layout in which I want to add a GLViewWidget object and then a GraphicsLayoutWidget. But when I add these widgets to the vertical box layout, the GraphicsLayoutWidget takes over the whole layout where I cannot see the GLViewWidget object. I've included the code below.
class view_manager(QtCore.QObject):
def __init__(self):
super(view_manager, self).__init__()
self._layout = QtGui.QVBoxLayout()
self._detectorView = viewport()
self._layout.addWidget(self._detectorView)
b = QtGui.QPushButton("HEY")
self._layout.addWidget(b)
self._plotView = self.getPlot()
self._layout.addWidget(self._plotView)
def getLayout(self):
return self._layout
def getPlot(self):
plot_widget = pg.GraphicsLayoutWidget()
#plot_widget.resize(800,350)
plt1 = plot_widget.addPlot()
plt2 = plot_widget.addPlot()
## make interesting distribution of values
vals = numpy.hstack([numpy.random.normal(size=500), numpy.random.normal(size=260, loc=4)])
## compute standard histogram
y,x = numpy.histogram(vals, bins=numpy.linspace(-3, 8, 40))
## Using stepMode=True causes the plot to draw two lines for each sample.
## notice that len(x) == len(y)+1
plt1.plot(x, y, stepMode=True, fillLevel=0, brush=(0,0,255,150))
## Now draw all points as a nicely-spaced scatter plot
y = pg.pseudoScatter(vals, spacing=0.15)
#plt2.plot(vals, y, pen=None, symbol='o', symbolSize=5)
plt2.plot(vals, y, pen=None, symbol='o', symbolSize=5, symbolPen=(255,255,255,200), symbolBrush=(0,0,255,150))
plot_widget.show()
return plot_widget
The detectorView object inherits from GLViewWidget. Any help would be greatly appreciated.
After extensive searching, I found the solution. Calling setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
from my GLViewWidget fixed this issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.