Adding Push Button to GraphicWindow

1,767 views
Skip to first unread message

magnetism87

unread,
Mar 27, 2014, 10:44:13 AM3/27/14
to pyqt...@googlegroups.com
Is there a way to add a push button to a GraphicWindow object? I have a GraphicWindow that is plotting realtime data, and I would like to add a "Pause" button to pause the plot. 
Currently, I create my GraphicWindow this way, but the last two lines throw an error when I try to add a QPushButton. I'd appreciate any advice:
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
...
win = pg.GraphicsWindow(title="Basic plotting examples")
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: Plotting')

pg.setConfigOptions(antialias=True)
label = pg.LabelItem(justify='center')
win.addItem(label)
p6 = win.addPlot(title="Updating plot", row=1, col=0)
curve = p6.plot(pen='y', shadowPen=pg.mkPen(cosmetic=False, width=4.5, color='r'))
curve.setShadowPen(color='r', width=3)
curve.setFillLevel(100)
p6.enableAutoRange('xy', False)
p6.setXRange(0,100)
p6.setYRange(0,1200)
p6.showGrid(1,1)

pauseBtn = QtGui.QPushButton('Pause')
win.addItem(pauseBtn)

Luke Campagnola

unread,
Mar 27, 2014, 11:09:35 AM3/27/14
to pyqt...@googlegroups.com
On Thu, Mar 27, 2014 at 10:44 AM, magnetism87 <magne...@gmail.com> wrote:
Is there a way to add a push button to a GraphicWindow object? I have a GraphicWindow that is plotting realtime data, and I would like to add a "Pause" button to pause the plot. 
Currently, I create my GraphicWindow this way, but the last two lines throw an error when I try to add a QPushButton. I'd appreciate any advice:

To embed a QWidget inside QGraphicsView, you first need to wrap it in a QGraphicsProxyWidget. See: http://qt-project.org/doc/qt-4.8/qgraphicsproxywidget.html

Another option is to simply position the button over the view (for example, `button.setParent(view)`) rather than placing it inside the view.


magnetism87

unread,
Mar 27, 2014, 2:34:23 PM3/27/14
to pyqt...@googlegroups.com
Thank you, Luke. The setParent() function was what I was looking for. Also, for anyone else with the same problem, you also have to call button.show() after setParent() to have the button be displayed 
Reply all
Reply to author
Forward
0 new messages