Hi all,
See the below working example. I am trying to put a QGraphicsRectItem on a
figure (eventually to be some polygons, but I kept it simple here). I want
the axis gridlines to be painted on top of this rectangle, however when I
do this the zooming with mouse functionality stops working. It seems there
may be something with the z order and what item is receiving the mouse
events/how they are handled?
Regards,
Stewart
from PyQt4 import QtCore, QtGui
import sys
import numpy as np
import pyqtgraph as pg
pg.setConfigOption('background', 'w'); pg.setConfigOption('foreground', 'k')
a = QtGui.QApplication([])
p = pg.PlotWidget()
line = p.plot( x = np.arange(400, 600), y = np.random.rand(200), pen = pg.
mkPen('r') )
p.setXRange(0, 1000)
p.setYRange(0, 1)
p.plotItem.getAxis('left').setGrid(255)
p.plotItem.getAxis('bottom').setGrid(255)
rect = QtGui.QGraphicsRectItem( QtCore.QRectF( QtCore.QPointF(0, 0), QtCore.
QSizeF(1000, 1.0) ) )
rect.setPen( pg.mkPen('b', width = 2) )
rect.setBrush( pg.mkBrush( ( 220, 220, 220 ) ) )
p.plotItem.addItem(rect)
rect.setZValue( line.zValue() - 1)
# By default, mouse-wheel zoom works in both x and y directions, but grid
is hidden below rect
# When uncommenting the below lines:
# Mouse-wheel zoom works when the mouse is over the x & y axis labels, but
when it is
# over the plot itself, zoom is only in the y direction
p.plotItem.getAxis('bottom').setZValue( rect.zValue() + 1 )
p.plotItem.getAxis('left').setZValue( rect.zValue() + 1 )
p.plotItem.getAxis('right').setZValue( rect.zValue() + 1 )
p.plotItem.getAxis('top').setZValue( rect.zValue() + 1 )
p.show()
sys.exit(a.exec_())
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/affd97b6-2af2-4506-891e-31d293ef885c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.