【问题标题】:PyQt: Adding multiple widgets to layoutPyQt:向布局添加多个小部件
【发布时间】:2018-08-14 16:55:55
【问题描述】:

我正在尝试使用 Pyqt 设置图形视图。我有一个垂直框布局,我想在其中添加一个 GLViewWidget 对象,然后添加一个 GraphicsLayoutWidget。但是当我将这些小部件添加到垂直框布局时,GraphicsLayoutWidget 接管了我看不到 GLViewWidget 对象的整个布局。我已经包含了下面的代码。

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

detectorView 对象继承自 GLViewWidget。任何帮助将不胜感激。

【问题讨论】:

  • 经过大量搜索,我找到了解决方案。从我的 GLViewWidget 调用 setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) 解决了这个问题。
  • 您必须编写解决方案并将其标记为正确,而不是评论

标签: python pyqt pyqtgraph


【解决方案1】:

经过大量搜索,我找到了解决方案。致电setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) 从我的 GLViewWidget 解决了这个问题。

【讨论】:

  • 另一个选项可能包括设置小部件的最小或最大高度......即self._detectorView.setMinimumHeight(HEIGHT)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-10
  • 1970-01-01
  • 2011-03-05
相关资源
最近更新 更多