Bugfix: ViewBox border drawing
- Fixed border overlapping (issue #316) - Added new method ViewBox.setBorder to complete API
This commit is contained in:
parent
7506ee3d3f
commit
b491f82006
@ -14,6 +14,7 @@ from ...Qt import isQObjectAlive
|
|||||||
|
|
||||||
__all__ = ['ViewBox']
|
__all__ = ['ViewBox']
|
||||||
|
|
||||||
|
|
||||||
class WeakList(object):
|
class WeakList(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -34,10 +35,12 @@ class WeakList(object):
|
|||||||
yield d
|
yield d
|
||||||
i -= 1
|
i -= 1
|
||||||
|
|
||||||
|
|
||||||
class ChildGroup(ItemGroup):
|
class ChildGroup(ItemGroup):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
ItemGroup.__init__(self, parent)
|
ItemGroup.__init__(self, parent)
|
||||||
|
self.setFlag(self.ItemClipsChildrenToShape)
|
||||||
|
|
||||||
# Used as callback to inform ViewBox when items are added/removed from
|
# Used as callback to inform ViewBox when items are added/removed from
|
||||||
# the group.
|
# the group.
|
||||||
@ -64,6 +67,12 @@ class ChildGroup(ItemGroup):
|
|||||||
listener.itemsChanged()
|
listener.itemsChanged()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def shape(self):
|
||||||
|
return self.mapFromParent(self.parentItem().shape())
|
||||||
|
|
||||||
|
def boundingRect(self):
|
||||||
|
return self.mapRectFromParent(self.parentItem().boundingRect())
|
||||||
|
|
||||||
|
|
||||||
class ViewBox(GraphicsWidget):
|
class ViewBox(GraphicsWidget):
|
||||||
"""
|
"""
|
||||||
@ -185,6 +194,11 @@ class ViewBox(GraphicsWidget):
|
|||||||
self.background.setPen(fn.mkPen(None))
|
self.background.setPen(fn.mkPen(None))
|
||||||
self.updateBackground()
|
self.updateBackground()
|
||||||
|
|
||||||
|
self.borderRect = QtGui.QGraphicsRectItem(self.rect())
|
||||||
|
self.borderRect.setParentItem(self)
|
||||||
|
self.borderRect.setZValue(1e3)
|
||||||
|
self.borderRect.setPen(self.border)
|
||||||
|
|
||||||
## Make scale box that is shown when dragging on the view
|
## Make scale box that is shown when dragging on the view
|
||||||
self.rbScaleBox = QtGui.QGraphicsRectItem(0, 0, 1, 1)
|
self.rbScaleBox = QtGui.QGraphicsRectItem(0, 0, 1, 1)
|
||||||
self.rbScaleBox.setPen(fn.mkPen((255,255,100), width=1))
|
self.rbScaleBox.setPen(fn.mkPen((255,255,100), width=1))
|
||||||
@ -428,8 +442,10 @@ class ViewBox(GraphicsWidget):
|
|||||||
self.updateViewRange()
|
self.updateViewRange()
|
||||||
self._matrixNeedsUpdate = True
|
self._matrixNeedsUpdate = True
|
||||||
self.background.setRect(self.rect())
|
self.background.setRect(self.rect())
|
||||||
|
self.borderRect.setRect(self.rect())
|
||||||
self.sigStateChanged.emit(self)
|
self.sigStateChanged.emit(self)
|
||||||
self.sigResized.emit(self)
|
self.sigResized.emit(self)
|
||||||
|
self.childGroup.prepareGeometryChange()
|
||||||
|
|
||||||
def viewRange(self):
|
def viewRange(self):
|
||||||
"""Return a the view's visible range as a list: [[xmin, xmax], [ymin, ymax]]"""
|
"""Return a the view's visible range as a list: [[xmin, xmax], [ymin, ymax]]"""
|
||||||
@ -1054,6 +1070,19 @@ class ViewBox(GraphicsWidget):
|
|||||||
def xInverted(self):
|
def xInverted(self):
|
||||||
return self.state['xInverted']
|
return self.state['xInverted']
|
||||||
|
|
||||||
|
def setBorder(self, *args, **kwds):
|
||||||
|
"""
|
||||||
|
Set the pen used to draw border around the view
|
||||||
|
|
||||||
|
If border is None, then no border will be drawn.
|
||||||
|
|
||||||
|
Added in version 0.9.10
|
||||||
|
|
||||||
|
See :func:`mkPen <pyqtgraph.mkPen>` for arguments.
|
||||||
|
"""
|
||||||
|
self.border = fn.mkPen(*args, **kwds)
|
||||||
|
self.borderRect.setPen(self.border)
|
||||||
|
|
||||||
def setAspectLocked(self, lock=True, ratio=1):
|
def setAspectLocked(self, lock=True, ratio=1):
|
||||||
"""
|
"""
|
||||||
If the aspect ratio is locked, view scaling must always preserve the aspect ratio.
|
If the aspect ratio is locked, view scaling must always preserve the aspect ratio.
|
||||||
|
Loading…
Reference in New Issue
Block a user