constrain legend rect to be fully inside viewbox; simplest solution to fix #113
This commit is contained in:
parent
cf1565f7d3
commit
a5216b1eed
@ -5,7 +5,7 @@ from pyqtgraph import (
|
|||||||
LinearRegionItem, mkBrush,
|
LinearRegionItem, mkBrush,
|
||||||
mkColor, mkPen,
|
mkColor, mkPen,
|
||||||
PlotDataItem,
|
PlotDataItem,
|
||||||
LegendItem,
|
LegendItem, ViewBox,
|
||||||
)
|
)
|
||||||
|
|
||||||
from nmreval.lib.colors import BaseColor, Colors
|
from nmreval.lib.colors import BaseColor, Colors
|
||||||
@ -472,11 +472,18 @@ class LegendItemBlock(LegendItem):
|
|||||||
def mouseDragEvent(self, ev):
|
def mouseDragEvent(self, ev):
|
||||||
if ev.button() == QtCore.Qt.LeftButton:
|
if ev.button() == QtCore.Qt.LeftButton:
|
||||||
ev.accept()
|
ev.accept()
|
||||||
|
|
||||||
dpos = ev.pos() - ev.lastPos()
|
dpos = ev.pos() - ev.lastPos()
|
||||||
|
|
||||||
|
upper_left = self.pos()
|
||||||
|
lower_right = self.pos()
|
||||||
|
lower_right.setX(lower_right.x() + self.width())
|
||||||
|
lower_right.setY(lower_right.y() + self.height())
|
||||||
|
|
||||||
vb_rect = self.parentItem().rect()
|
vb_rect = self.parentItem().rect()
|
||||||
pos = self.pos()
|
|
||||||
# upper left corner and a point a little more to the bottom right must be inside
|
# upper left and lower right corner must be inside viewbox
|
||||||
if vb_rect.contains(pos+dpos) and vb_rect.contains(pos+dpos+QtCore.QPointF(20., 20.)):
|
if vb_rect.contains(upper_left + dpos) and vb_rect.contains(lower_right + dpos):
|
||||||
self.autoAnchor(pos + dpos)
|
self.autoAnchor(upper_left + dpos)
|
||||||
else:
|
else:
|
||||||
self.autoAnchor(pos)
|
self.autoAnchor(upper_left)
|
||||||
|
Loading…
Reference in New Issue
Block a user