GLViewWidget.itemsAt() now measures y from top of widget.

This commit is contained in:
Luke Campagnola 2014-02-10 20:51:17 -05:00
parent c8ee4a86be
commit 032c6c625d
2 changed files with 21 additions and 2 deletions

View File

@ -15,6 +15,8 @@ pyqtgraph-0.9.9 [unreleased]
- Renamed GraphicsView signals to avoid collision with ViewBox signals that
are wrapped in PlotWidget: sigRangeChanged => sigDeviceRangeChanged and
sigTransformChanged => sigDeviceTransformChanged.
- GLViewWidget.itemsAt() now measures y from top of widget to match mouse
event position.
New Features:
- Added ViewBox.setLimits() method

View File

@ -129,6 +129,12 @@ class GLViewWidget(QtOpenGL.QGLWidget):
return tr
def itemsAt(self, region=None):
"""
Return a list of the items displayed in the region (x, y, w, h)
relative to the widget.
"""
region = (region[0], self.height()-(region[1]+region[3]), region[2], region[3])
#buf = np.zeros(100000, dtype=np.uint)
buf = glSelectBuffer(100000)
try:
@ -140,12 +146,12 @@ class GLViewWidget(QtOpenGL.QGLWidget):
finally:
hits = glRenderMode(GL_RENDER)
items = [(h.near, h.names[0]) for h in hits]
items.sort(key=lambda i: i[0])
return [self._itemNames[i[1]] for i in items]
def paintGL(self, region=None, viewport=None, useItemNames=False):
"""
viewport specifies the arguments to glViewport. If None, then we use self.opts['viewport']
@ -294,6 +300,17 @@ class GLViewWidget(QtOpenGL.QGLWidget):
def mouseReleaseEvent(self, ev):
pass
# Example item selection code:
#region = (ev.pos().x()-5, ev.pos().y()-5, 10, 10)
#print(self.itemsAt(region))
## debugging code: draw the picking region
#glViewport(*self.getViewport())
#glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT )
#region = (region[0], self.height()-(region[1]+region[3]), region[2], region[3])
#self.paintGL(region=region)
#self.swapBuffers()
def wheelEvent(self, ev):
if (ev.modifiers() & QtCore.Qt.ControlModifier):