TickSliderItem: Use Tick.removeAllowed (#1441)
* Fix: TickSliderItem ignores Tick.removeAllowed This prohibits removing ticks from a `TickSliderItem` if they were set to `tick.removeAllowed=False`. Test code: ```python3 import pyqtgraph as pg from pyqtgraph.Qt import QtCore import numpy as np app = pg.mkQApp() class CustomWidget(pg.GraphicsView): def __init__(self, parent=None, *args, **kargs): pg.GraphicsView.__init__(self, parent, useOpenGL=False, background=None) self.item = pg.TickSliderItem(*args, **kargs) for pos in (0, 0.5, 1): tick = self.item.addTick(pos) tick.removeAllowed = False # Possibility 1 # Possibility 2 for tick, value in self.item.listTicks(): tick.removeAllowed = False self.setCentralItem(self.item) self.setFixedHeight(31) w = CustomWidget() w.show() app.exec_() ``` * Make 'removeAllowed' regular property of 'Tick' Co-authored-by: 2xB <2xB@users.noreply.github.com>
This commit is contained in:
parent
01aee93a16
commit
75048c473b
@ -210,7 +210,7 @@ class TickSliderItem(GraphicsWidget):
|
||||
self.sigTicksChangeFinished.emit(self)
|
||||
|
||||
def tickClicked(self, tick, ev):
|
||||
if ev.button() == QtCore.Qt.RightButton:
|
||||
if ev.button() == QtCore.Qt.RightButton and tick.removeAllowed:
|
||||
self.removeTick(tick)
|
||||
|
||||
def widgetLength(self):
|
||||
@ -766,7 +766,6 @@ class GradientEditorItem(TickSliderItem):
|
||||
color = self.getColor(x)
|
||||
t = TickSliderItem.addTick(self, x, color=color, movable=movable, finish=finish)
|
||||
t.colorChangeAllowed = True
|
||||
t.removeAllowed = True
|
||||
|
||||
return t
|
||||
|
||||
@ -872,6 +871,7 @@ class Tick(QtGui.QGraphicsWidget): ## NOTE: Making this a subclass of GraphicsO
|
||||
self.pen = fn.mkPen(pen)
|
||||
self.hoverPen = fn.mkPen(255,255,0)
|
||||
self.currentPen = self.pen
|
||||
self.removeAllowed = True
|
||||
self.pg = QtGui.QPainterPath(QtCore.QPointF(0,0))
|
||||
self.pg.lineTo(QtCore.QPointF(-scale/3**0.5, scale))
|
||||
self.pg.lineTo(QtCore.QPointF(scale/3**0.5, scale))
|
||||
|
Loading…
x
Reference in New Issue
Block a user