I'm using PySide on OSX 10.7 with Python 2.7. I have an application I've been writing for some time which has a UI consiting of a QGraphicsScene which frequently repopulated itself with items, as well as many QWidgets I've written with custom drawing code (nothing too fancy, just a lot of pixmap drawing, text, and rectangles).
[snip]
However, I've noticed a few strange things since adding pyqtgraph to my project:1) The splash screen I wrote to come up when my app launched has started showing up as a blank image. It was a transparent png. If I comment out the pyqtgraph imports, it displays as usual.2) And the most alarming: with pyqtgraph imported in my project, at seemingly spurious moments while I'm using the application, (while my non pyqtgraph QGraphicsScene is repopulating, or when I click the window containing my custom widgets [paint events]). The entire window will 'flash' or 'flicker'. Now, this is actually somewhat of a misnomer - what actually appears to be happening is that the entire buffer is inverting and drawing flipped across the horizontal center axis -- the window will draw upside down for one frame. I've seen this happen before in my app when I've screwed something up in a custom paint routine, like forgetting to call QPainter.end().
Any ideas? Some things I can think of:Do I need to be calling QApplication.setGraphicsSystem to something? Could that be an issue?
Is this actually not a bug with pyqtgraph, but rather something about including pyqtgraph has caused a piece of my drawing code that was incorrect but was previously rendering alright to fail?
My only current solution is to totally decouple my pyqtgraph plotting from the rest of my application, and communicate data over a socket, which is a huge bummer. So, any help would be most appreciated.
I should also point out I do not need OpenGL support - I'm only plotting in 2d and do not plan to utilize GL at all.
import numpy as np
import pyqtgraph as pg
from pyqtgraph import QtGui, QtCore
def main ():
try:
app = QtGui.QApplication([])
print("no problems panning")
except RuntimeError:
app = QtGui.QApplication.instance()
print("panning will flicker-invert when panning")
# generate some fake data
x = np.arange(-8,8,0.01)
y = np.cos(10*x)*np.exp(-np.abs(x))
curve = pg.PlotCurveItem(x=x,y=y)
plot_widget = pg.PlotWidget()
plot_widget.plotItem.addItem(curve)
plot_widget.show()
app.exec_()
main()
I'm experiencing the same problem. Below is some code which recreates the problem. The first time I run it (i.e. when the QApplication is actually instanciated) then the panning/zooming works just fine (attached "Regular View.png") but the second time (i.e. when the QApplication.instance() is used) then when panning/zooming causes the buffer to flicker between regular and inverted (attached "Inverted View.png").
import numpy as np
import pyqtgraph as pg
from pyqtgraph import QtGui, QtCore
def main ():
try:
app = QtGui.QApplication([])
print("no problems panning")
except RuntimeError:
app = QtGui.QApplication.instance()
print("panning will flicker-invert when panning")
# generate some fake data
x = np.arange(-8,8,0.01)
y = np.cos(10*x)*np.exp(-np.abs(x))
curve = pg.PlotCurveItem(x=x,y=y)
plot_widget = pg.PlotWidget()
plot_widget.plotItem.addItem(curve)
plot_widget.show()
app.exec_()
main()
def mkQApp():global QAPPinst = QtGui.QApplication.instance()if inst is None:QAPP = QtGui.QApplication([])else:QAPP = instreturn QAPP
import numpy as np
import pyqtgraph as pg
from pyqtgraph import QtGui, QtCore
def main ():
app = pg.mkQApp()
# generate some fake data
x = np.arange(-8,8,0.01)
y = np.cos(10*x)**2*np.exp(-np.abs(x))
curve = pg.PlotCurveItem(x=x,y=y)
plot_widget = pg.PlotWidget()
plot_widget.plotItem.addItem(curve)
plot_widget.show()
app.exec_()
main()
def exec_app ():
t_finish = time.time()+60*0.5
while time.time() < t_finish:
QtGui.QApplication.processEvents()
time.sleep(0.05)
print("done updating")
# then put in the lines:
# thread = threading.Thread(target=exec_app,name='QtAppExec')
# thread.start()
# thread.join()
# instead of
# app.exec_()
Hi,
I tried using the pg.mkQApp but got the same behavior
import numpy as np
import pyqtgraph as pg
from pyqtgraph import QtGui, QtCore
def main ():
app = pg.mkQApp()
# generate some fake data
x = np.arange(-8,8,0.01)
y = np.cos(10*x)**2*np.exp(-np.abs(x))
curve = pg.PlotCurveItem(x=x,y=y)
plot_widget = pg.PlotWidget()
plot_widget.plotItem.addItem(curve)
plot_widget.show()
app.exec_()
main()
I think app.exec_() needs to be called once after each instance of QApplication. I tried using QApplication.processEvents() to update the plot but something's missing which won't allow for pan/zooming afterwards (Note: I tried threading the processEvents() into a loop called every fraction of a second but that didn't allow for updating the pan/zoom either).