Is there a selection widget that I can add to a plot window. Here is the flow I need to implement:When the user (presses some key [maybe ctrl]. It can't be the mouse click button since that already controls zoom) and moves the mouse, One vertical infinite line appears and as the mouse gets moved the region selected by the mouse gets highlighted. When the key is released a handler is called with the selected x, y (in data points) coordinates of the selected region. Using this, I would open another pyqtgraph window with more detailed charts for the selected region.
On Sat, Mar 31, 2012 at 10:22 AM, pyqtgraphuser <webus...@gmail.com> wrote:Is there a selection widget that I can add to a plot window. Here is the flow I need to implement:When the user (presses some key [maybe ctrl]. It can't be the mouse click button since that already controls zoom) and moves the mouse, One vertical infinite line appears and as the mouse gets moved the region selected by the mouse gets highlighted. When the key is released a handler is called with the selected x, y (in data points) coordinates of the selected region. Using this, I would open another pyqtgraph window with more detailed charts for the selected region.What you want sounds a lot like a LinearRegionItem.
import pyqtgraph as pgfrom PyQt4 import QtCorepw = pg.plot()lr = pg.LinearRegionItem()lr.hide()pw.addItem(lr)vb = pw.plotItem.vb ## get the viewbox from the plot itemdef drag(ev):global vb, lrif (ev.button() == QtCore.Qt.LeftButton) and (ev.modifiers() & QtCore.Qt.ControlModifier):lr.show()lr.setRegion([vb.mapToView(ev.buttonDownPos()).x(), vb.mapToView(ev.pos()).x()])ev.accept()else:pg.ViewBox.mouseDragEvent(vb, ev)vb.mouseDragEvent = drag
Thanks. How would I open the selected region in a completely new plot
window?
This is just a repeat of code you've already used--Create a new plot by any method (pg.plot(), pg.PlotWidget, GraphicsLayout.addPlot, etc.) then plot your data there and set the bounds with the setRange method.
Ok I get it now. here is the example code I have so far. How do I capture a key release event (some way to capture release of the ctrl key) on the viewbox. I tried this and did not work:def release(ev):#somehow capture releasewin = pg.GraphicsWindow()label = pg.LabelItem(justify='right')win.addItem(label)p1 = win.addPlot(row=1, col=0)p1.plot(data1, pen="r")vb.keyReleaseEvent = release
From a user interaction perspective, I think it would be more natural to open the window when the mouse is released, rather than the ctrl button (but this is just my preference and either option should work).
Hello, I was trying to implement the code below on a viewBox itself (from a 2D plot, not a regular one)
But I'm failing..., I think the linear region is being displayed below my image and not above... =/Any suggestions?
Em domingo, 1 de abril de 2012 02h21min18s UTC+1, Luke Campagnola escreveu:import pyqtgraph as pgfrom PyQt4 import QtCorepw = pg.plot()lr = pg.LinearRegionItem()lr.hide()pw.addItem(lr)vb = pw.plotItem.vb ## get the viewbox from the plot itemdef drag(ev):global vb, lrif (ev.button() == QtCore.Qt.LeftButton) and (ev.modifiers() & QtCore.Qt.ControlModifier):lr.show()lr.setRegion([vb.mapToView(ev.buttonDownPos()).x(), vb.mapToView(ev.pos()).x()])ev.accept()else:pg.ViewBox.mouseDragEvent(vb, ev)vb.mouseDragEvent = drag
---- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]---
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 pyqtgraph+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
It partially helps... xP
Now it's in front but it's not really a box-region but an infinity one (see image) and is permanent... (if I use .hide() it doesn't show at all)Here's my code:def mouseDragEvent(self, ev):if ev.button() == Qt.RightButton:ev.ignore()else:# Make region appearregion = pg.LinearRegionItem()region.setZValue(99)self.addItem(region)region.setRegion([ self.mapToView(ev.buttonDownPos()).x(), self.mapToView(ev.pos()).x() ])pg.ViewBox.mouseDragEvent(self, ev)
with self being a ViewBox
Well, I was trying to implement that because the RectMode doesn't show the selected region... (I'm currently using RectMode as well)
Another question about ViewBox (sorry if it's not completely related, I just don't think it's appropriate to just go creating new topics all the time... xP)
But how can I identify the items of a ViewBox? With the .allChildren() I can see all of them, but I have multiple ImageItems that I can't keep track of the items themselves (just the data inside as they are loaded by the user) but I would like to change their opacity, zlevel and data itself... (and the same with HistogramLUTItem)
On Wed, Jul 10, 2013 at 6:07 AM, Pedro Paiva <p3k...@gmail.com> wrote:Well, I was trying to implement that because the RectMode doesn't show the selected region... (I'm currently using RectMode as well)Can you explain this further? Under what circumstances does RectMode not work?
Another question about ViewBox (sorry if it's not completely related, I just don't think it's appropriate to just go creating new topics all the time... xP)
But how can I identify the items of a ViewBox? With the .allChildren() I can see all of them, but I have multiple ImageItems that I can't keep track of the items themselves (just the data inside as they are loaded by the user) but I would like to change their opacity, zlevel and data itself... (and the same with HistogramLUTItem)Sorry, I don't follow. What is wrong with allChildren(), and why can't you keep track of the items?
Em quarta-feira, 10 de julho de 2013 15h53min11s UTC+1, Luke Campagnola escreveu:On Wed, Jul 10, 2013 at 6:07 AM, Pedro Paiva <p3k...@gmail.com> wrote:
Well, I was trying to implement that because the RectMode doesn't show the selected region... (I'm currently using RectMode as well)Can you explain this further? Under what circumstances does RectMode not work?RectMode doesn't show the area being selected (while dragging the mouse)
viewbox.rbScaleBox.setZValue(1e9)
Another question about ViewBox (sorry if it's not completely related, I just don't think it's appropriate to just go creating new topics all the time... xP)
But how can I identify the items of a ViewBox? With the .allChildren() I can see all of them, but I have multiple ImageItems that I can't keep track of the items themselves (just the data inside as they are loaded by the user) but I would like to change their opacity, zlevel and data itself... (and the same with HistogramLUTItem)Sorry, I don't follow. What is wrong with allChildren(), and why can't you keep track of the items?allChildren() returns everything inside a ViewBox and if I have several images in there I didn't know wich is wich...Now I'm adding a marker in every image as img.setData(0, 'img name') so when I ask for the children I also check img.data(0) to match the name and then find the children I need to work with...