PytQtGraph - 添加布局和按钮

时间:2016-05-11 19:23:58

标签: python pyqt qpushbutton pyqtgraph

我试图在一个简单的PyQtGraph情节中展示,在不同位置展示四个QPushButtons。我阅读了PyQtGraphPyQt的文档,我可以得到这个:

enter image description here

但我需要做的是这样的事情:

enter image description here

这是我的代码:

class MyApplication(QtGui.QApplication):
  def __init__(self, *args, **kwargs):
    super(MyApplication, self).__init__(*args, **kwargs)

    self.win = pg.GraphicsWindow()

    self.plot = self.win.addPlot(title='Timed data')
    self.curve = self.plot.plot()

    self.tmr = QTimer()
    self.tmr.timeout.connect(self.update)
    self.tmr.start(0)

    self.layout = QtGui.QHBoxLayout()
    self.layout.setParent(self.win)

    self.saveBtn = QtGui.QPushButton("Save")
    self.saveBtn.setParent(self.win)
    self.saveBtn.show()

    self.pauseBtn = QtGui.QPushButton("Pause")
    self.pauseBtn.setParent(self.win)
    self.pauseBtn.show()

    self.stopBtn = QtGui.QPushButton("Stop")
    self.stopBtn.setParent(self.win)
    self.stopBtn.show()

    self.closeBtn = QtGui.QPushButton("Close")
    self.closeBtn.setParent(self.win)
    self.closeBtn.show()

def main():
  app = MyApplication(sys.argv)
  sys.exit(app.exec_())

if __name__ == '__main__':
  main()

我怎样才能做到这一点?希望你能帮帮我。

1 个答案:

答案 0 :(得分:0)

我正在尝试运行您的代码,并找到问题的解决方案。但是,您提供的代码似乎并不完整。你能填写缺少的部分吗?

from PyQt4 import QtCore
from PyQt4 import QtGui
import pyqtgraph as pg



class MyApplication(QtGui.QApplication):

    def __init__(self, *args, **kwargs):
        super(MyApplication, self).__init__(*args, **kwargs)
        self.win = pg.GraphicsWindow()

        self.plot = self.win.addPlot(title='Timed data')
        self.curve = self.plot.plot()

        self.tmr = QtCore.QTimer()
        self.tmr.timeout.connect(self.update)
        self.tmr.start(0)

        self.layout = QtGui.QHBoxLayout()
        self.layout.setParent(self.win)

        self.saveBtn = QtGui.QPushButton("Save")
        self.saveBtn.setParent(self.win)
        self.saveBtn.show()

        self.pauseBtn = QtGui.QPushButton("Pause")
        self.pauseBtn.setParent(self.win)
        self.pauseBtn.show()

        self.stopBtn = QtGui.QPushButton("Stop")
        self.stopBtn.setParent(self.win)
        self.stopBtn.show()

        self.closeBtn = QtGui.QPushButton("Close")
        self.closeBtn.setParent(self.win)
        self.closeBtn.show()


if __name__== '__main__':
    myApp = MyApplication(?,?) # What arguments should I fill in here?

我希望我可以帮助你。

亲切的问候, 克里斯托夫