TickSliderItem

33 views
Skip to first unread message

blake nusbickel

unread,
Sep 6, 2019, 11:13:14 AM9/6/19
to pyqtgraph
Hi,

I am a novice at pyqtgraph.  I would like to add a TickSliderItem to the vertical axis of a plot that I can move up and down.  I am making a DIY oscilloscope GUI and would like to use a slider to indicate the trigger point.  The only example I see on the web that uses TickSliderItem uses it with GradientEditorItem and "attaches" it with setCentralItem(), but I can't figure out what I would use to attach it to the y scale of a plot.  Can anyone help me with this?

The following is an extract of one of the examples, with "ts" being TickSliderItem that I somehow need to attach:

import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
from pyqtgraph.Point import Point

#generate layout
app = QtGui.QApplication([])
win = pg.GraphicsWindow()
win.setWindowTitle('pyqtgraph example: crosshair')
label = pg.LabelItem(justify='right')
win.addItem(label)
p2 = win.addPlot(row=1, col=0)

ts = pg.TickSliderItem()
#view.setCentralItem(ts)
ts.addTick(0.5, 'r')

#create numpy arrays
#make the numbers large to show that the xrange shows data from 10000 to all the way 0
data1 = 10000 + 15000 * pg.gaussianFilter(np.random.random(size=10000), 10) + 3000 * np.random.random(size=10000)

p2.plot(data1, pen="w")

## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

Regards,
Blake

Patrick

unread,
Sep 9, 2019, 11:09:58 PM9/9/19
to pyqtgraph
Hi,

Just a thought, all the functionality you want can be provided by an InfiniteLine, you just want the level to be indicated with a triangle/marker on the axis rather than a line across the plot. So maybe copy the code from InfiniteLine as a base, but modify the bounding box and paint methods etc to draw the marker instead. You could probably also cut out a lot of the other functionality you don't need to simplify it a bit.

Patrick
Reply all
Reply to author
Forward
0 new messages